Upload and Validate an Image in PHP

Upload and Validate an 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

9 Comments on “Upload and Validate an Image in PHP”

  1. I loved how you explained step by step process of validating an image. I feel like every day I learn something new through my blog!

Leave a Reply

Your email address will not be published. Required fields are marked *