PHP

Image Upload with PDO

Image Upload with PDO

Lets see how the Image Upload going to work with PDO and mysql. By using PHP predefined function move_uploaded_file() we can move the uploaded file and rename it and move to the folder.

Steps :

1. Create a Database. Example “Testing”
2. Create a Table. Example “avatars”.
3. Create a Fields. Example “id, name, avatar”
4. Create a HTML form to Upload a image.
5. Connect Database
6. Upload a image and move to folder and store a path in database.

Here is my HTML form.

Don’t forget to add for attribute enctype=”multipart/form-data” which is mandatory for file upload.

Here is Sample Full Source to upload, rename image using PDO.

Image-Upload-with-PDO-sample

Thanks!.