【问题标题】:How to upload a video in Laravel? [duplicate]如何在 Laravel 中上传视频? [复制]
【发布时间】:2018-08-25 19:06:54
【问题描述】:

我正在尝试上传视频,并且我的数据库中正确存储了路径,但我没有在我想要的文件夹中获得视频。

这是我的代码:

$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();
        }

现在可以上传了,但是在强调文件名的情况下,我在这一行遇到了问题,文件名被更改了

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

例如:Présentation -> Présentation !!! 因此,当我想显示上传的视频时,这会产生问题

【问题讨论】:

  • 什么是“我想要的文件夹”?我假设 /storage/app

标签: laravel file file-upload


【解决方案1】:

检查https://laravel.com/docs/5.6/filesystem#file-uploads, 这里的文档解释了如何处理各种文件相关的东西。

基本示例是

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

然后,当你在其他地方获取文件时

// here you should already have fetched $postmedia

Storage::get($postmedia->path);

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2020-06-27
  • 1970-01-01
  • 1970-01-01
  • 2011-10-29
  • 2019-04-16
  • 2014-08-07
  • 1970-01-01
  • 2015-03-25
相关资源
最近更新 更多