Re: upload multi images in laravel

See all posts Reply

Re: upload multi images in laravel new!
by Ethar Shrouf, 1 year, 3 months ago
i use laravel , ajax to multi upload file,
but there is an error message: "Invalid argument supplied for foreach()"
when i use dd($request->file; its print file name successfully
public function upload(Request $request) {
  $files = array();
  $f=$request->file;
  foreach ($f as $k => $l) {
     foreach ($l as $i => $v) {
       if (!array_key_exists($i, $files))
        $files[$i] = array();
      $files[$i][$k] = $v;
    }
  }
Reply
Re: upload multi images in laravel new!
by colin, 1 year, 3 months ago
The code you are using is for vanilla PHP uploads. If you are using Laravel, you should do something like:
if($request->hasFile('file')) {
  $files = $request->file('file');
  foreach ($files as $file) {
    $filename = $file->getClientOriginalName();
    $handle = new Upload($filename);
    // ....
  }
}
Reply