upload images through a simple form

This tutorial will show you how to upload an image and give it a name in a simple form, first you’ll need a database table to store the title and path to the image, create the following structure in phpmyadmin:

Next connect to your database:

Check to see if the form has been submitted if so then run the code

Check the lengh if the title, if to small or to long generate an error which we will print out later

Set a path to store images in:

Next move the uploaded image from the tmp directory to your chosen destination only if the image is a .gif,.png or ,jpg

if validation is okay then carry on

Next get the title from the form and remove any tags and make it safe for database entry:

Next insert the title and image path into the database, show a sucess message and close the 2 if statements.

display any errors

Finally the form itself make sure the form has enctype=”multipart/form-data” or no upload will happen.

Here’s the full script:

 

Tags:,