artisticre's avatar

Image Upload Not working

When I try to upload an image, it creates the image name as a folder and then a .tmp file in the folder. Not sure what I did.

if($request->hasfile('avatar'))
       {
           $destination = 'uploads/profile/'.$user->avatar;
           if(File::exists($destination)){
               File::delete($destination);
           }
           $file = $request->file('avatar');
           $extension= $file->getClientOriginalExtension();
           $filename = time() . '.'.$extension;
           $file->move('uploads/profile/'.$filename);
           $user->avatar = $filename;
       }

0 likes
4 replies
thinkverse's avatar

There is a whole section of files section in the documentation for requests, also a section on file uploads on the filesystem documentation you might wanna look at, that could give you some help. 🙂

chiefguru's avatar

@artisticre I don't trust the original filename, so I just use the upload filename.

$path = $request->file('video_file')->store('videos/temp_upload_store', 's3-blogs');

tinkeshwar's avatar

Hi, If you are looking for something like the Laravel Imager package on Github as tinkeshwar/laravel-image Happy to help.

Please or to participate in this conversation.