4

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');
}
4
  • Have you tried with the same file? Check the file size of his video and check what the servers max upload file size is (and check if you got a size limitation in your form, as well). Commented Oct 4, 2016 at 14:26
  • @MagnusEriksson thank you, apparently it just server upload limit configuration. after change it, it work like a charm Commented Oct 4, 2016 at 14:49
  • That's usually the case... :) Commented Oct 4, 2016 at 14:52
  • that was not the case for me, what is the problem? any more solutions please? Commented Jan 31, 2022 at 7:47

2 Answers 2

8

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

Sign up to request clarification or add additional context in comments.

Comments

1

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):

  • upload_max_filesize 10M
  • post_max_size 10M

.htaccess (Apache):

  • php_value upload_max_filesize 10M
  • php_value post_max_size 10M

Then restart Apache sudo systemctl restart httpd.service (Cent OS 7)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.