Webiondev123's avatar

Laravel uploading a .tmp file instead of image

Hi.

My laravel upload is uploading this file when I try to upload image:

C:\wamp64\tmp\phpA304.tmp

$validated=$request->validate( [
            'description' => 'required|string|max:255',
            'category' => 'required',
            'deadline' => 'required|date',
            'verify'=>'required',
            'file' => 'mimes:jpeg,png,bmp,gif,svg,mp4,qt',


        ]);

           $need=new Table;
           $need->fill($validated);
           $need->fill(['user_id'=> \Auth::user()->id]);
           
           if($need->save()) {

           return Redirect::to('somewhere');

      }
0 likes
3 replies
skliche's avatar
skliche
Best Answer
Level 42

@Webiondev123 You have to use store() or storeAs() to move it to the location where you want your uploaded files to be stored, see https://laravel.com/docs/master/requests#storing-uploaded-files

Addendum: "Files will, by default be stored in the server's default temporary directory, unless another location has been given with the upload_tmp_dir directive in php.ini." (Source: http://php.net/manual/en/features.file-upload.post-method.php)

Snapey's avatar

php always uploads to a temporary file first

sevenTopo's avatar

will i had the same probleme today ...in my view i have input with name "image" when i tried to upload it and move it after i got the same error so my solution was so simple i have to recuperate the name of my image and the extension and put the file in my storage directory (public_path).

$request->file('image')->move(public_path('img/test'),$request->file('image')->getClientOriginalName().".".$request->file('image')->getClientOriginalExtension()); return $request->file('image')->getClientOriginalName();

Please or to participate in this conversation.