1

I'm uploading a CSV (65KB) through a form on my site, parsing it with papaparse and then POSTing it with ajax to my server:

console.log(csv)
// if everything is ok, send via AJAX to process with PHP
$.ajax({
    type: "POST",
    url: "scripts/batch_objects.php",
    dataType: 'json',
    data: {'Data': csv},
    success: function(result){
        $("#batchResult").html(result);
    },
    error: function(result) {
        $("#batchResult").html(result);
    },
});

In the console, I can see that the CSV is properly uploaded and parsed - it confirms that all the rows (435 of them) are set in the csv var. On the server side I've got a quick script to check things out:

<?php
    $csv = $_POST['Data'];
    echo count($csv);
?>

However on the server side I'm only getting 143 of the rows (the output of the echo statement), instead of all 435.

I've tried setting php_value post_max_size 20M in my .htaccess but that hasn't helped.

Constantino
  • 2,243
  • 2
  • 24
  • 41

1 Answers1

0

The following fixed things for me (found inspiration here):

// get our data together
var postData = {};
postData.Table = table;
postData.Action = action;
postData.Data = csv;

// if everything is ok, send via AJAX to process with PHP
$.ajax({
    type: "POST",
    url: "scripts/batch_objects.php",
    contentType: "application/json",
    data: JSON.stringify(postData),
    success: function(result){
        $("#batchResult").html(result);
        console.log("Success " + result);
    },
    failure: function(result) {
        $("#batchResult").html('ERROR: ' + result);
        console.log('Eror ' + result);
    },
});

Then on the sever side you can access the POST data with:

$post_data = json_decode($HTTP_RAW_POST_DATA);
Community
  • 1
  • 1
Constantino
  • 2,243
  • 2
  • 24
  • 41