0

I'm trying to upload a video and I get the path stored correctly in my database but I don't get the video in the folder that I want.

Here is my code:

$postvideo     = Postmedia::where('post_id',$id)->where('type','video')->first();

        if (isset($postvideo)) 
        {

            if ($request->video_link) {
                $postvideo->path = $request->video_link;
                $postvideo->typevid = $request->link;
            }
            else
            {
                File::delete($postvideo->path);
                if($request->hasFile('video_link_local'))
                    {

                        $file               = $request->file('video_link_local');
                        $filename           = $file->getClientOriginalName();
                        $path               = 'uploads/post/';
                        $file->move($path, $filename);
                        $postvideo->path    = $path.$filename;
                        $postvideo->ext     = ($request->video_link_local)->getClientOriginalExtension();
                        $postvideo->typevid = $request->local;


                    }
            }
            $postvideo->save();
        }

the upload now works but in the case of accentuated filenames i get a problem in this line the name of the file is changed

$file->move($path, $filename);

like this for example : Présentation -> Présentation !!! So this creates a problem when i want to show the uploaded video

Youssef Boudaya
  • 887
  • 2
  • 17
  • 29

1 Answers1

1

Check https://laravel.com/docs/5.6/filesystem#file-uploads , here docs explain how to handle all kind of file related stuff.

base example is

$file = $request->file('video_link_local');
$filename = $file->getClientOriginalName();
$path = '/uploads/post/';
$upload_path = Storage::putFileAs($path, $file, $filename);
$postmedia->path = $upload_path;

Then, when getting the file somewhere else where you have

// here you should already have fetched $postmedia

Storage::get($postmedia->path);
Sérgio Reis
  • 2,483
  • 2
  • 19
  • 32