user3810794
user3810794

Reputation: 273

multiple file upload from postman in laravel

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.

Upvotes: 3

Views: 8783

Answers (1)

Manoj Rammoorthy
Manoj Rammoorthy

Reputation: 1430

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

Upvotes: 3

Related Questions