MattB's avatar
Level 2

Storage to 2 places

Can "file -> move" be used to pass in a 2nd argument so that the same form can push requested files to 2 different locations? What I have right now is:

if($file = $request->file('image')){
          $name = $file->getClientOriginalName();
          $path = 'images';
          if($file->move($path, $name)){
            $newartpack = new artpack();
            $newartpack->thumbnail = '/' . $path . '/' . $name;
            $newartpack->name = $request->name;
            $newartpack->description = $request->description;
            $newartpack->price = $request->price;
            $newartpack->save();
            return redirect()->route('admin.artpacks.index');
          };
        };

This just handles one image upload, but can I do something like this to also accept and move a zip file to go along with it:

if($file = $request->file('image')){
          $name = $file->getClientOriginalName();
          $pathOne = 'images';
      $pathTwo = 'some other path here';
          if($file->move($pathOne, $pathTwo, $name)){
            $newartpack = new artpack();
            $newartpack->thumbnail = '/' . $pathOne . '/' . $name;
            $newartpack->artzip = '/' . $pathTwo . '/' . $name;
            $newartpack->name = $request->name;
            $newartpack->description = $request->description;
            $newartpack->price = $request->price;
            $newartpack->save();
            return redirect()->route('admin.artpacks.index');
          };
        };
0 likes
1 reply
bobbybouwmann's avatar

You will have to call $file->move twice, there is no way that you can move to files at once. The reason because of this is that you call move on the file itself. A given file can only move to one place at the same. The same thing that you can only be on the same place at once!

You can create your own method that does the moves and check if both are true!

Please or to participate in this conversation.