3

I am trying to upload multiple files but I only get 1 file in return.Below is my code:

public function uploadQuoteItemImage(){
 $file=Input::file('filename');

 $file_count=count($file);
  dd($file_count);
$uploadcount=0;

foreach($file as $f){
 $random_name=str_random(8);
 $destinationPath='images/';
 $extension=$file->getClientOriginalExtension();

 $filename=$random_name.'_quote_itm_image.'.$extension;  
 $byte=File::size($file); //get size of file

 $uploadSuccess=Input::file('filename')->move($destinationPath,$filename);
 $uploadcount ++;

}
if ($uploadcount == $file_count){
 QuoteItemImage::create(array(
     'quote_item_id'=>Input::get('quote_item_id'),
     'filename'=>$filename,
    'filesize'=>$byte
     ));
 return Common::getJsonResponse(true, 'image created', 200);
    }
}

enter image description here Even though I sent 3 files its returning only 1 file. Please help.

1
  • 2
    Is your file input name array (name[])? eg. <input type="file" name="filename[]" multiple> Commented Jun 22, 2016 at 12:35

1 Answer 1

3

so in the form-data of postman you are giving the key attribute as filename for files in turn it should be filename[] since you are sending array of data once you set it it works fine .

now you can check in the php code like below

$files = Input::file('filename');
foreach ($files as $one) {
   $filename       = $one->getClientOriginalName();
   $listfilenames[] = $filename;
                }
echo $listfilenames
Sign up to request clarification or add additional context in comments.

1 Comment

The important point here is the name of the request parameter that holds files. It should be paramName[], ending with open and close square brackets.

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.