how to add multiple images in php

Solutions on MaxInterview for how to add multiple images in php by the best coders in the world

showing results for - "how to add multiple images in php"
Clara
03 Sep 2016
1if (isset($_POST['submit'])) {
2    $j = 0; //Variable for indexing uploaded image 
3
4    $target_path = "uploads/"; //Declaring Path for uploaded images
5    for ($i = 0; $i < count($_FILES['file']['name']); $i++) { //loop to get individual element from the array
6
7        $validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed
8        $ext = explode('.', basename($_FILES['file']['name'][$i])); //explode file name from dot(.) 
9        $file_extension = end($ext); //store extensions in the variable
10
11        $target_path = $target_path.md5(uniqid()).
12        ".".$ext[count($ext) - 1]; //set the target path with a new name of image
13        $j = $j + 1; //increment the number of uploaded images according to the files in array       
14
15        if (($_FILES["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded.
16            && in_array($file_extension, $validextensions)) {
17            if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) { //if file moved to uploads folder
18                echo $j.
19                ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
20            } else { //if file was not moved.
21                echo $j.
22                ').<span id="error">please try again!.</span><br/><br/>';
23            }
24        } else { //if file size and file type was incorrect.
25            echo $j.
26            ').<span id="error">***Invalid file Size or Type***</span><br/><br/>';
27        }
28    }
29}
30
queries leading to this page
upload multiple images in php mysqlphp upload multiple imagesupload multiple images in phpadd multiple image and view in phpupload multiple image in phpupload multiple images with html form in phphow to upload multiple images and display in phpmultiple image upload in phphow to update multiple images in phpphp multiple image uploadhow to add more then one picture on phpinsert multi image and image description in phpphp merge two imageshow to upload multiple photos using phpdisplay multiple images phpinsert multi image and iamge description in phphow to upload multiple images in mysql using phphow to upload multiple image using phpphp to upload multiple imagesmulti image insert in phpupload multi image phphow to muve multiple images in phphow upload multiple image in phphow to upload multiple image in phpcombine two images phphow to upload and display multiple images in phpinsert multi image and image name in phpupload multiple image and display in phphow to upload multiple images in phpphp multiple images uploadhow to upload multiple images in php using for loophow to upload multiple images in mysql and show on the product using phphow to upload and display multiple image in phpupload multiple images php scriptmultiple image upload in php demohow to auto resize multiple image in phphow to multi image insert in php llophow to set limit on upload multiple images with phpupload multiple image phphow to upload multiple images in php mysqladd multiple image in phpmerge two images and output phphow to upload multiple images and show in phpupload multiple images phpadd multiple images in phphow to access multiple images uploaded in phphow to add multiple images in php