A
A
Anton2019-03-07 21:58:38
Laravel
Anton, 2019-03-07 21:58:38

How to load multiple files at once in Laravel and display the name of each?

Hello everyone, I ran into a problem uploading files to the server, actually uploading something, but the name of each file, I don’t even know how to display it ..
CODE:

foreach ($r->file('img_other') as $f) {
          $f->move($destinationPath,$f->getClientOriginalName());
          Good::where('id', $good->id)->update([
            "img1" => $f->getClientOriginalName(), //1 файл
            "img2" => $f->getClientOriginalName() // 2 файл
    ]);
        }

For example, he chose 2 files, he downloads them, but how to display the name of each uploaded file, something doesn’t reach ..
In PHP, everything was simpler, I used it like this
$total = count($_FILES['uploaded_file']['name']);

    if($total != '0'){

      // Loop through each file
      for($i=0; $i<$total; $i++) {
        //Get the temp file path
        $tmpFilePath = $_FILES['uploaded_file']['tmp_name'][$i];
        //Make sure we have a filepath
        if ($tmpFilePath){
          //Setup our new file path
          $newFilePath = $uploaddir . $_FILES['uploaded_file']['name'][$i];

          //Upload the file into the temp dir
          if(move_uploaded_file($tmpFilePath, $newFilePath)) {
            mysql_query("UPDATE `goods` SET `img1`='".$_FILES['uploaded_file']['name'][0]."', `img2`='".$_FILES['uploaded_file']['name'][1]."');
          }
        }
      }
    }

I also tried to do it in Lark, alas, nothing happened :s

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Ernest Faizullin, 2019-03-07
@erniesto77

$request->allFiles('images');

N
netrox, 2019-03-07
@netrox

$allImages = $request->allFiles();
$firstImage = $allImages[0];
$secondImage = $allImages[1];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question