CodeIgniter Forums
max_size fails - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: max_size fails (/showthread.php?tid=80139)



max_size fails - sfarzoso - 09-17-2021

PHP Code:
I have this input:

    <input id="delega" type="file" class="form-control" accept="application/pdf">

I send the pdf using an AJAX request:

var 
data JSON.stringify($('input[name="post_data"]').val());

    var url = `<?= base_url('appointments/ajax_register_appointment') ?>`;
    var $layer = $('<div/>');

    let formData = new FormData();
    formData.append('post_data'data);

    if (GlobalVariables.manageMode) {
        formData.append('exclude_appointment_id'GlobalVariables.appointmentData.id);
    }

    let delega document.getElementById('delega').files[0];
    if (delega !== undefined) {
        formData.append('delega'delega);
    }

    $.ajax({
            urlurl,
            method'post',
            dataformData,
            dataType'json',
            contentTypefalse,
            processDatafalse,

But if I upload a file of 172kb I get the error that is too large:

        $delega $this->request->getFile('delega');

        // controlla correttezza file
        if (!empty($delega)) {

            
            $validationRules 
= [
                'delega'        => 'mime_in[delega,application/pdf]|max_size[1024]'
            ];

            if (!$this->validate($validationRules)) {
                return $this->fail($this->validator->getErrors());
            }
        }

how is that possible



RE: max_size fails - iRedds - 09-17-2021

Example from the documentation https://codeigniter.com/user_guide/libraries/validation.html#rules-for-file-uploads
max_size[field_name,2048]


RE: max_size fails - InsiteFX - 09-18-2021

post_max_size:

Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize
Generally speaking, memory_limit should be larger than post_max_size.
PHP Default: 8M

upload_max_filesize:

The maximum size of an uploaded file
PHP Default: 2M


RE: max_size fails - sfarzoso - 09-18-2021

I have post_max_size to 100M, same for upload_max_filesize, and memory_limit is 32M
I followed the documentation so this should be correct:

'delega' => 'mime_in[delega,application/pdf]|max_size[1024]'

but why it fails?


RE: max_size fails - InsiteFX - 09-18-2021

try:

PHP Code:
max_size[4096]

Each 1024 is in kb so 4096 is 4kb 



RE: max_size fails - sfarzoso - 09-18-2021

4096 kb are 4.096 mb


RE: max_size fails - InsiteFX - 09-19-2021

Did you check to see what the size of the file is?

Only other thing that will give you error is if the mime type is not recognized.


RE: max_size fails - sfarzoso - 09-19-2021

I fixed using max_size[delega,1024]


RE: max_size fails - InsiteFX - 09-20-2021

Glad you got it working.