I'm trying upload video in laravel. When it does upload it, it keeping saving file as php3d58.tmp and not mp4. Help me? I've been trying since yesterday and I've got nothing.
1 Answer
Use the storeAs() method to save uploaded file and getClientOriginalExtension() to get original file extension:
$path = $request->file('video')->storeAs(
'videos_directory',
$request->file('video')->getClientOriginalName() . '.' . $request->file('video')->getClientOriginalExtension()
);
16 Comments
Alexey Mezenin
@StephanyRocks what exactly doesn't work? Do you get an error?
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Auth; use App\User; class FileController extends Controller { // public function store(Request $request){ $file=$request->file('file'); $filename=time() . '.' .$file->getClientOriginalExtension(); $destinationpath=storage_path('/introvideo',$filename); $file->getPathName(); $file->move($destinationpath); $user=Auth::user(); $user->profilepicture=$file=$filename; $user->save(); } }
Alexey Mezenin
@StephanyRocks looks like you literally used
$request->file('video'). But it's just an example. Use $request->file('file') instead of $request->file('video'). |