2

I m trying to upload multiple photos using

<input type='file'>

with same name to the input element like,

<?php
$remainGal  =   $maxGallery-$totalGallery;
if($remainGal>0){
?>
<div class="businessSPGItems">
<form name="addBusinessGallery" method="post" action="businessservices.php#messageGallery" enctype="multipart/form-data">
<input type="hidden" name="businessID" value="<?php echo $businessID;?>" />
<?php
for($i=0; $i<$remainGal; $i++){
?>
<input type="file" name="filePhotos[]" style="margin-top:5px;" tabindex="<?php echo $i+5; ?>" /><br />
<?php
}
?>
<input type="submit" name="btnAddGallery" value="Add" style="margin-top:10px;" tabindex="<?php echo $i+5; ?>" />
</form>
</div>
<?php
}
?>

But the problem is when i m taking the total count of the file element it always shows 5... ie.,

<?php 
$photos     =   $_FILES["filePhotos"];
echo count($photos);
?>

So i could not upload more than 5 photos at a time.... i dont know i m doing the correct method.. help please,, thanks...

8
  • Not an answer, but have you considered a more advanced upload control like PLUpload? Commented Sep 28, 2012 at 5:01
  • I m new in PHP, i dont heard about that.. Commented Sep 28, 2012 at 5:06
  • Look at the output of var_dump($photos); instead. Commented Sep 28, 2012 at 5:12
  • I guess the value of $remainGal is set to 5. Apparently, there will be 5 file HTML controls in your HTML. I suggest you use some advanced file upload input controls like PLUpload, SWFUpload. Commented Sep 28, 2012 at 5:16
  • 1
    @SherinJose count($_FILES["filePhotos"]["name"]) should work. If uploading nothing throws a notice, you could wrap it in a conditional: if (empty($_FILES["filePhotos"]["name"]) == FALSE) { count($_FILES["filePhotos"]["name"]); } Commented Sep 28, 2012 at 5:23

1 Answer 1

1

Your $_FILES["filePhotos"]; will have an array of values.

Read: http://php.net/manual/en/features.file-upload.multiple.php

...the arrays $_FILES['userfile'], $_FILES['userfile']['name'], and $_FILES['userfile'] ['size'] will be initialized... Each of these will be a numerically indexed array of the appropriate values for the submitted files.

$_FILES["filePhotos"]["name"][0];
$_FILES["filePhotos"]["name"][1];
$_FILES["filePhotos"]["name"][2];
$_FILES["filePhotos"]["name"][3];
$_FILES["filePhotos"]["name"][4];

Also note that there is an upload limit config value. http://php.net/manual/en/ini.core.php#ini.max-file-uploads

The maximum number of files allowed to be uploaded simultaneously. Starting with PHP 5.3.4, upload fields left blank on submission do not count towards this limit.

It defaults to 20.

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.