How to upload and validate a image in php

In this tutorial I will explain how to upload a image and how to validate image extension
Create a HTML form with two text field :

  • One is for Image title with input type text.
  • Second one is for upload image with input type file.For file upload input must be file(type=”file”). This input type show the file select control.


HTML form must have following attributes :

  • method=”post”
  • enctype=”multipart/form-data” (The enctype attribute specifies how the form-data should be encoded when submitting it to the server.)

without these attributes , the image upload will not work.

Create a database with name imagesdata. Inside this database we create a table with name tblimages.
SQL Script for tblimages—

Now create a database connection file(config.php)

PHP Script for getting posted  values,  image validation, move images into directory and  insertion data into database

Demo——————————————-

View Demo

How to run this script 

  1. Download the zip
  2. Extract zip file and put in the root directory
  3. open phpmyadmin. Create a db imagesdata then import SQL file(given inside the package)

Download full source Code(How to upload and validate a image in php)
Size: 28 KB
Version: V 1.0

Anuj Kumar

I'm Anuj kumar a web developer with 4+ year experience .I write blogs in my free time. I love to learn new technologies and share with others. I founded PHPGurukul in September 2015. The main aim of this website to is provide php , jquery , mysql , phpoops and other web development tutorials. I am trying best effort to make PHPGurukul useful for every single moment spend on this website. If you think this website is useful to visit please share with your friend and buddies.

Recommended Tutorials for you

You may also like...