Upload Multiple Images In Php

[Solved] Upload Multiple Images In Php | Php - Code Explorer | yomemimo.com
Question : how to add multiple images in php

Answered by : open-orangutan-o4m5n4ba1d6h

if (isset($_POST['submit'])) { $j = 0; //Variable for indexing uploaded image $target_path = "uploads/"; //Declaring Path for uploaded images for ($i = 0; $i < count($_FILES['file']['name']); $i++) { //loop to get individual element from the array $validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed $ext = explode('.', basename($_FILES['file']['name'][$i])); //explode file name from dot(.) $file_extension = end($ext); //store extensions in the variable $target_path = $target_path.md5(uniqid()). ".".$ext[count($ext) - 1]; //set the target path with a new name of image $j = $j + 1; //increment the number of uploaded images according to the files in array if (($_FILES["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded. && in_array($file_extension, $validextensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) { //if file moved to uploads folder echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>'; } else { //if file was not moved. echo $j. ').<span id="error">please try again!.</span><br/><br/>'; } } else { //if file size and file type was incorrect. echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>'; } }
}

Source : https://stackoverflow.com/questions/24895170/multiple-image-upload-php-form-with-one-input/24895361 | Last Update : Wed, 29 Sep 21

Question : Multiple Image Upload PHP form with one input

Answered by : victorious-vole-euzwpfdp83pj

$error=array();
$extension=array("jpeg","jpg","png","gif");
foreach($_FILES["files"]["tmp_name"] as $key=>$tmp_name) { $file_name=$_FILES["files"]["name"][$key]; $file_tmp=$_FILES["files"]["tmp_name"][$key]; $ext=pathinfo($file_name,PATHINFO_EXTENSION); if(in_array($ext,$extension)) { if(!file_exists("photo_gallery/".$txtGalleryName."/".$file_name)) { move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"photo_gallery/".$txtGalleryName."/".$file_name); } else { $filename=basename($file_name,$ext); $newFileName=$filename.time().".".$ext; move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"photo_gallery/".$txtGalleryName."/".$newFileName); } } else { array_push($error,"$file_name, "); }
}

Source : https://stackoverflow.com/questions/24895170/multiple-image-upload-php-form-with-one-input | Last Update : Mon, 12 Sep 22

Question : Multiple Image Upload PHP form with one input

Answered by : victorious-vole-euzwpfdp83pj

<form action="create_photo_gallery.php" method="post" enctype="multipart/form-data"> <table width="100%"> <tr> <td>Select Photo (one or multiple):</td> <td><input type="file" name="files[]" multiple/></td> </tr> <tr> <td colspan="2" align="center">Note: Supported image format: .jpeg, .jpg, .png, .gif</td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Create Gallery" id="selectedButton"/></td> </tr> </table>
</form>

Source : https://stackoverflow.com/questions/24895170/multiple-image-upload-php-form-with-one-input | Last Update : Mon, 12 Sep 22

Answers related to upload multiple images in php

Code Explorer Popular Question For Php