slickness's avatar

Upload files

Something is wrong with the upload. When I upload a file is not the uploaded file stored but a .temp file. What did I do wrong?

if($request->hasFile('video')) {
                $video = $request->file('video');
                $filename = time() . '.' . $video->getClientOriginalExtension();
                File::makeDirectory('storage/'. Auth::id() .'/posts/video/', 0775, true, true);
                $video->move('storage/'. Auth::id() .'/posts/video/');

                $post->video = ('/'. Auth::id() . '/posts/video/' . $filename);
            }
0 likes
3 replies
ejdelmonico's avatar

You don't have to make a directory of storage unless you want a custom directory under storage/app/public. Just store the file and then make sure you run php artisan storage:link and it will be available in public/storage. Laravel stores the file in storage/app/public.

slickness's avatar

Thank you for your answer. Unfortunately, the problem was not solved, the files are saved as a .temp file.

jcmargentina's avatar
Level 8

check this code and my modification to yours:

           if($request->hasFile('video')) {
                $video = $request->file('video');
                $filename = time() . '.' . $video->getClientOriginalExtension();
                File::makeDirectory('storage/'. Auth::id() .'/posts/video/', 0775, true, true);
                $video->move('storage/'. Auth::id() .'/posts/video/', $filename); //here is the modification

                $post->video = ('/'. Auth::id() . '/posts/video/' . $filename);
            }

Please or to participate in this conversation.