MattB's avatar
Level 2

Image uploads to tmp instead of correct location

Using the below code, it should upload to the path specified in $path but for some reason, it saves the links to all pictures to c:\xampp\tmp with the .tmp extension but will move them to the correct folder anyway. What have I done wrong?

public function store(Request $request){
        //
        if($file = $request->file('image')){
          $name = $file->getClientOriginalName();
          $path = 'public/images';
          if($file->move($path, $name)){
            $post = new Gallery();
            $post->image = $request->image;
            $post->name = $request->name;
            $post->species_id = $request->species_id;
            $post->tag = $request->tag;
            $post->patreon = $request->tag;
            $post->save();
            return redirect()->route('admin.gallery.index');
          };
        };
    }
0 likes
5 replies
Dunsti's avatar
$name = $file->getClientOriginalName();
$path = 'public/images';
...
$post->name = $request->name; // here you should use $path . '/' . $name instead
ftiersch's avatar

What do you mean exactly?

Files are first stored in the tmp directory since they are uploaded before your PHP code is executed so the server needs to store them somewhere in between.

MattB's avatar
Level 2

@DUNSTI - Hi, thanks for the reply, but I'm afraid I don't understand sorry. What would the new line look like?

Dunsti's avatar
Dunsti
Best Answer
Level 6
$post->name = $path . '/' . $name;

because in $request->name is still the temp-name.

Please or to participate in this conversation.