Welcome Guest, Not a member yet? Register   Sign In
max_size fails
#1

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
Reply
#2

Example from the documentation https://codeigniter.com/user_guide/libra...le-uploads
max_size[field_name,2048]
Reply
#3

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
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

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?
Reply
#5

try:

PHP Code:
max_size[4096]

Each 1024 is in kb so 4096 is 4kb 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

4096 kb are 4.096 mb
Reply
#7

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#8

I fixed using max_size[delega,1024]
Reply
#9

Glad you got it working.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB