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.
Yes something about save as() method. But let me Show you what I have first. This is my code am I doing something wrong?
– Jan 28 '18 at 15:49
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();
}
}
– Jan 28 '18 at 15:49
@StephanyRocks looks like you literally used `$request->file('video')`. But it's just an example. Use `$request->file('file')` instead of `$request->file('video')`.
– Alexey MezeninJan 28 '18 at 16:10
public function store(Request $request){
$path = $request->file('file')->storeAs(
'videos_directory',
$request->file('file')->getClientOriginalName() . '.' . $request->file('file')->getClientOriginalExtension()
);
$user=Auth::user();
$user->profilepicture=$file=$path;
$user->save();
}
– Jan 28 '18 at 16:24
The code will save the video to `videos_directory` directory. Change it to any other directory you want to save to.
– Alexey MezeninJan 28 '18 at 16:40
OK. One last thing i want to display the video on the screen how do i do that? This is how i want to display it
but what do i put for the source?
– Jan 28 '18 at 16:46
To be able to do that, you need to [create a symbolic link](https://stackoverflow.com/a/48176373/1227923) between `storage/your_video_directory` and `public/your_video_directory`. Then you'll be able to display the video on a web page with something like ``
– Alexey MezeninJan 28 '18 at 16:53
Ok, I'm sorry to keep asking you all these questions but i'm having another issues the image saves to the directory but its saved as php8F1C.php while on the database it saves as introvideo/islands2.mp4. So how am I supposed to display it?
– Jan 28 '18 at 17:23
@StephanyRocks when you use `storeAs()` as I've shown, the file will be stored with the name you've defined. You can check the documentation on [file uploading](https://laravel.com/docs/5.5/filesystem#file-uploads)
– Alexey MezeninJan 28 '18 at 17:25
storeAs() is not saving the file name but as tmp file. What do I do? I really need you to guide me in this. I have a big project to complete on this and you seem like the only person helping me.
– Jan 28 '18 at 18:55
@StephanyRocks I'm sorry, but I don't know why it doesn't work. `storeAs()` always worked for me. I think you need to create a new question and explain there what exactly happens when you're uploading a file. Maybe someone will be able to help with that.
– Alexey MezeninJan 28 '18 at 19:27
Omg!! I see that it works Thank you Thank you Thank you!!!!... But I cant display the video on the screen its not showing. I used
– Jan 28 '18 at 19:41