0

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.

1
  • Is your form element inside a table element? Commented Aug 25, 2012 at 20:52

1 Answer 1

1

Change your name attribute On the input element from:

name="uploadFile"

To:

name="uploadFile[]"

Only one file is being inserted into the $_FILES array

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.