Posting Array to PHP file from Node, Array is Truncated on Page

Viewed 20

I'm loading a large amount of data into a Node array. Then, I'm passing that data to a PHP page like this:

const rows = res.data.values;
axios.post('./template.php', qs.stringify({rows}))
    .then((res) => {
        console.log(res.data);
        fs.writeFileSync('test.php', res.data, 'utf-8');
    })

Then, when I get to test.php, the $_POST variable is only the first 100 entries of my array I just passed.

I noticed when debugging and using console.log() to print the same array, I was getting something that said "... 19 more items". I was able to resolve that by calling this:

 util.inspect.defaultOptions.maxArrayLength = null;

At the top of my function. This worked great to stop the "... 19 more items" and now the full array displays with console.log(), however, it seems to have had no effect on my POST.

I'm stumped as to what I'm missing here -- does anyone know why my array is getting truncated when doing the POST? Thanks!

1 Answers

Something like this

   let objectData = [{a: 1, b: 2}, {a: 5, b:6}]; 
   axios.post(url, objectData, {
      headers: {
        "Content-Type": "application/json"
      }
    })

and at the PHP side, read the raw INPUT

$json = file_get_contents('php://input');
$data = json_decode($json);
Related