0

I'm getting crazy understanding which is the problem.

I need to send some data to the php server, so that the PHP controller can save them in a text file.

This is the javascript code in the view:

$.ajax({
    dataType: 'json',
    url: '<?php echo site_url("/Controller/save_file") ?>/'+filename_json,
    cache: false,
    data: reportData,
    type: "POST",
    success: function (data, status, xhr)
    {
        console.log(data);
        if(data[0].status == 'success') {
            echo 'ok';
        }
    },
    error: function(jqXHR, textStatus, errorThrown) {
        echo 'error';
    }
});

The backend is a CodeIgniter PHP application. Here the controller that keep and process the request public function save_report_jsonfile() { $jsonFile = $this->uri->segment('3');

    $tmp_file = set_realpath("./file_json/", true).$jsonFile.".json";
    // here in the real controller there is the code that save the file_json/
    // file_put_contents($tmp_file, json_encode($_POST))
    
    // only for debug purpose
    echo json_encode($_POST);

    exit;
}

The issue is that in the saved file .json and also in the returned encoded $_POST, I have only a first part of the sent reportData. I don't understand if I have some limit in data posted lenght.

I tried to use console.log($.param(reportData)) in the javascript part and I'm getting a string of about 89.000 chars; actually my php server run 7.3.2 and post_max_size is 8M. If I chech in chrome developing tools, in the Network tab, I see the ajax call and if I explpore its details, in the header information I can see that the "form data" posted are complete and not truncated like that saved to the file.

Hoping I was quite clear. Any idea about the solution?

Kind regards, Matt

agodoo
  • 409
  • 6
  • 21
  • Is this a limit with the Apache server ? https://stackoverflow.com/questions/2364840/what-is-the-size-limit-of-a-post-request#:~:text=By%20default%2C%20the%20post%20request,file%20(php%20configuration%20setting). – Vanquished Wombat Nov 24 '20 at 12:35
  • _“a string of about 89.000 chars”_ - containing what? If we are talking about URL-encoded form parameters/variables here, then `max_input_vars` and `max_input_nesting_level` might also play a role here, aside from mere _size_ constraints. – CBroe Nov 24 '20 at 12:45
  • @VanquishedWombat I think this is not an issue because the $.param() responses with a string of about 89000 char a lot minus then 8M post_max_size actually setted on my test server. – agodoo Nov 24 '20 at 13:05
  • @CBroe you are correct! I have a json object, with multilivel inside. I changed max_input_var to 5000 and it worked. How input var count is calculated on a json object? – agodoo Nov 24 '20 at 14:02
  • It’s not, it applies to $_POST here. If you are sending a lot of individual input fields, or fields with names that generated a nested structure (like `name="foo[bar][baz][15]"`), then these settings come into play. They got nothing to do with JSON itself. – CBroe Nov 24 '20 at 14:08

0 Answers0