In this tutorial I will explain how to upload a image and how to validate image extensionCreate an 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.
XHTML12345678910111213141516Image Title:Upload Image :Create a database with name imagesdata. Inside this database we create a table with name tblimages.SQL Script for tblimages—
MySQL123456CREATE TABLE IF NOT EXISTS `tblimages` ( `id` int(11) NOT NULL, `ImagesTitle` varchar(120) DEFAULT NULL, `Image` varchar(150) DEFAULT NULL, `PostingDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;Now create a database connection file(config.php)
PHP123456789101112PHP Script for getting posted values, image validation, move images into directory and insertion data into database
PHP12345678910111213141516171819202122232425262728293031323334