Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 file upload validation

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');
}
like image 275
Mahendra Kurniawan Avatar asked Feb 07 '23 00:02

Mahendra Kurniawan


1 Answers

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

like image 168
Tohid Dadashnezhad Avatar answered Feb 08 '23 14:02

Tohid Dadashnezhad