dimanche 17 janvier 2016

laravel5.1 check size of upload (validator fails on validate size)

Is there a way to check the size of a file uploaded to the server? I tried to use this code:

$validator = Validator::make($request->all(), [
    'departments' => 'exists:departments,id',
    'attachment' =>'min:1|max:1500|mimes:txt,text,log,jpeg,bmp,png',

    ]);

    if ($validator->fails()) 
       return back()->withErrors($validator)->withInput();

When I try to upload for example the GIT setup (around 29MB), the upload works and I get a warning message from PHP. I've set maximum upload size of file to 8MB in php.ini. I want to show the user a message saying file is too big. The Problem I noticed is the large file isn't registered by the validator? Any idea how I can validate this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire