我已经搜索了如何上传视频和音频,但是我正在堆叠,请帮忙,这是代码。
public function store(Request $request)
{
$this->validate($request,[
'name' => 'required',
'file' => 'required|mimes:mpeg,3gp,ogg,mp4,webm,3gp,mov,flv,avi,wmv,ts|nullable|max:100040'
]);
if($request->hasFile('file'))
{
$filenameWithExt = $request->file('file')->getClientOriginalName();
$filename = pathinfo($filenameWithExt,PATHINFO_FILENAME);
$extension = $request->file('file')->getClientOriginalExtension();
$fileNameToStore = $filename.'_'.time().'.'.$extension;
$path = $request->file('file')->storeAs('public/file',$fileNameToStore);
}
else
{
$fileNameToStore = 'No Video selected please! check and try again.';
}
$vids = new Video;
$vids->name = $request->input('name');
$vids->file = $request->input('file');
// $vids->user_id = auth()->user()->id;
$vids->file = $fileNameToStore;
$vids->save();
return redirect('/videos')->with('success','Video Upload');
}