如何通过laravel移动视频文件


how to move video file by laravel

我试图通过File::move…将mp4视频从一个目录移动到另一个目录。。。但是源视频和移动的视频在移动之后停止工作。

PHP:

$from="assets/vids/".$filename."";
try{
    mkdir("assets/vids/USER".Auth::user()->id."");
} catch(Exception $e){}
$to="assets/vids/USER".Auth::user()->id."/".$filename."";
try{
    File::move($from,$to);
} catch(Exception $e){}

HTML:

<form action="{{ URL::route('end-video') }}" method="post" id="end-live-form" enctype="multipart/form-data" files>
    <input type="hidden" id="input-timer" name="timer">
    <a type="submit" id="end-btn">إنهاء البث</a>
    <div id="end-sure">
        <p>هل انت متأكد من انهاء البث</p>
        <button type="submit" id="end-live-btn">نعم</button>
        <a class="no">لا</a>
    </div>
    {{ Form::token() }}
</form>

您可以尝试PHP:rename函数。我认为这更容易。这不会损坏文件。

或者将mkdir更改为mkdir("assets/vids/USER".Auth::user()->id, 0755);

-编辑-

试试这个:

$from = "assets/vids/".$filename;
$to = "assets/vids/USER".Auth::user()->id."/".$filename;
try {
    mkdir("assets/vids/USER".Auth::user()->id, 0755);
    File::move($from, $to);
} catch(Exception $e){
    echo 'Caught exception: ',$e->getMessage(),"'n";
}

让我们看看有什么例外。

-结束编辑-