Site icon WDB24

How to upload multiple images in PHP and store in Mysql

php featured image

Multiple images uploading option is very handy if you want to upload more than one image at a time. Because multiple images upload option save lots of time of the user.

In this tutorial I am going to show you how to upload multiple images in PHP and store in mysql. I am going to create dynamic input fields using jquery and save them in mysql table.

How Upload multiple Images in PHP works:

Also read:


Create Mysql Database:

Create Mysql Table:

Upload Form HTML:

File upload form must have enctype=”multipart/form-data” attritube.

jQuery Code:

PHP Code:

$targetFolder holds the “Uploads” directory name. $errorMsg and $successMsg are arrays of error and success messages. Then I started loop on $_FILES and checked $fileArray['name'] and $fileArray['error'] must not be empty and zero. $getFileExtension holds the extension of images. If user upload any file other than image code will print an error. Then i checked size of image which should not more than 500kb. $breakImgName is used to break the image name. $newFileName is used to create new image name by using strotime and str_replace function. $targetPath variable holds the new image path. move_uploaded_file function is used to move image from temporary storage to the targeted path. If image moved properly then image name is saving to the images table.

All upload multiple images Code together

Also read:

Exit mobile version