Reputation: 59
I'm using laravel built in file upload to upload video to my website. I've already successfully uploaded the file, but when my friend try to upload the video he got an error "validation.uploaded" i don't know why this is happening and i've been trying to find the error but i can't find it. We both try it in firefox and chrome but only my friend who got it. Please help this is my code:
Save Video Function
protected function saveVideo(UploadedFile $video)
{
$fileName = str_random(40);
$fullFileName = $fileName.'.'.$video->guessClientExtension();
$video->storeAs('videos', $fileName);
return $fullFileName;
}
Save From Form
public function update(Request $request, $id)
{
//dd($request->all());
$video = Video::findOrFail($id);
$this->validate($request, [
'title' => 'required|unique:lessons,title,'.$video->id,
'lesson_lists' => 'required',
'description' => 'required'
]);
$data = $request->only('title', 'description','lesson_lists');
$data['slug'] = str_slug($request->title);
if($request->hasFile('image')){
$data['image'] = $this->saveImage($request->file('image'));
if($video->image !== '') $this->deletePhoto($video->image);
}
if($request->hasFile('video')){
$data['video'] = $this->saveVideo($request->file('video'));
if($video->video !== '') $this->deleteVideo($video->video);
}
//$data['lesson_id'] = implode($request->get('lesson_lists'));
$video->update($data);
Session::flash("flash_notification", [
"level"=>"success",
"message"=>"Berhasil menyimpan $video->title"
]);
return redirect()->route('video.index');
}
Upvotes: 4
Views: 15018
Reputation: 69
Laravel responses 422 Unprocessable Entity which response body contains validation.uploaded
due to exceed upload size limitation. Try to set proper value for following possible parameters(e.g. 10M):
/etc/php.ini
(PHP):
.htaccess
(Apache):
Then restart Apache sudo systemctl restart httpd.service
(Cent OS 7)
Upvotes: 1
Reputation: 1938
Actually if the size of file you try to download exceeds the "upload_max_filesize" the Laravel shows this validation error, so you must open the php.ini file and set the options like this:
post_max_size = 500M
upload_max_filesize = 500M
Notice: if you use wamp or xamp don't forget to restart it otherwise rerun the command:
php artisan serve
Upvotes: 8