ziben69
141
2
Laravel

How to secure file uploads

Posted 5 months ago by ziben69

Hello guys I have done tutorial to upload image files from link: https://laraveldaily.com/upload-multiple-files-laravel-5-4/

But how can I secure file uploads in view. Something like communicate when user will upload file more than 2MB?

Fragment of create.blade.php:

 <div class="form-group">
        <input type="file" name="photos[]" multiple aria-describedby="fileHelp"/>
        <small id="fileHelp" class="form-text text-muted">jpeg, png, bmp - 2MB.</small>
 </div>

and rules:

public function rules()
    {
        $rules = [
            'header' => 'required|max:255',
            'description' => 'required',
            'date' => 'required',
        ];
        $photos = $this->input('photos');
        foreach(range(0, $photos) as $index) {
            $rules['photos.' . $index] = 'image|mimes:jpeg,bmp,png|max:2000';
        }
 
        return $rules;
    }

all ok but when I try now to upload file which have got more than 2MB it gives me error:

Illuminate \ Http \ Exceptions \ PostTooLargeException
No message

How can I solve this? Thanks for help.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.