I am trying to upload multiple photos to my server, I have it partially working, it will do one photo, but it's not doing every photo that is passed through.
The HTML:
<form>
<input type="file" name="uploadFile" class="upload" multiple="true" onChange="galleryUpload(this.form,'ajax/add/gallery_photos.php'); return false;"/>
</form>
The PHP:
$photos = array();
$i = 0;
foreach($_FILES as $file)
{
$fileArr = explode("." , $file["name"]);
$ext = strtolower($fileArr[count($fileArr)-1]);
$allowed = array("jpg", "jpeg", "png", "gif", "bmp");
if (in_array($ext, $allowed)){
$source = $file['tmp_name'][$i++];
$path = "../../photos/";
$filename = uniqid();
//Crop photo etc..
if(move_uploaded_file($_FILES['uploadFile']['tmp_name'], "$path/$filename.jpg"))
{
$photos[] = array(
'photoID' => $photoID,
'URL' => $filename
);
}
}
}
echo json_encode($photos);
As you see, I also return json data of the photos uploaded, so I can manage them with jQuery (this is a sort of "ajax" upload form, so the page doesn't reload) so I need to return that data. so it needs to return the array of data. Everything seems to be working fine though with just one file, but it only will do one, even when I select multiple photos.