1
votes

I am having some trouble uploading a file - excel file.

I am using this rule in laravel 5.5 for max file size 3MB. According to the documentation the value must be in KB.

// Max file size: 3MB (3000 KB)
$validator = Validator::make($request->all(), [
    'Feed' => 'file|max:3000',
]);
if ($validator->fails()) {
        return Redirect::back()->withErrors(['File to big!']);
    }

In php.ini i have:

upload_max_filesize=3M

The file which i want to upload is 2.3 MB.

What i did wrong on validation?

UPDATE

Displaying the $_FILES['Feed'] for the file that i want to upload (original.xls = 2.3MB)

array:5 [
 "name" => "original.xls"
 "type" => ""
 "tmp_name" => ""
 "error" => 1
 "size" => 0
]

"error" => 1

and upload another small file 5.6 KB:

array:5 [
 "name" => "test.xls"
 "type" => "application/vnd.ms-excel"
 "tmp_name" => "/tmp/phpJUJfy4"
 "error" => 0
 "size" => 5632
]

"error" => 0 and i can see the size for it

UPDATE 2

If i start to delete from the excel file and get max: 2MB, the file uploads with no errors.

Why? 2.0 MB uploads the file and 2.1 MB NOT???

2
Have you seen any error?Lovepreet Singh
yes....the error that i returned: "File to big!"calin24
Have you tried with only 'Feed' => 'max:3000',Faizan Fayaz
Check the errors returned in the validator itself.Oluwatobi Samuel Omisakin
@OluwatobiSamuelOmisakin the validator itself: "The feed failed to upload." and tried only with max:3000 and the same errorcalin24

2 Answers

0
votes

the problem was in php.ini

On my server (ubuntu 18.04) i am using php 7.1 and changed the

upload_max_filesize=3M

only from apache2/php.ini file from:

/etc/php/7.1/apache2/php.ini

When i changed in the other one (cli) now works:

/etc/php/7.1/cli/php.ini
0
votes

When file send to server a browser use MIME encoding to convert all non-printable bytes to printable chars. This encoding increase file size.

So, when you send 2.3Mb file its actual size become more than 3Mb.