My code processes a .txt file that contains approximately 50,000 clients, which I must enter into a table using the MySQL batching mechanism "LOAD DATA LOCAL INFILE" (Bulk Insert in the Sql Server's world or MongoDb)
My code works fine if I do it from the same browser, but if I do the same with an Ajax call, it returns me "false", so I imagine that an apache or PHP security reason blocks me from executing this procedure. Does anyone know what I should do?
My code is:
<?php
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
error_reporting(E_ALL);
ini_set("display_errors", 1);
$mysqli = new mysqli('127.0.0.1', 'user_name', 'secret', 'prueba');
$file = $_POST["file"];
if ($mysqli->connect_errno) {
echo "Errno: " . $mysqli->connect_errno . "
";
echo "Error: " . $mysqli->connect_error . "
";
exit;
}
$sql = "LOAD DATA LOCAL INFILE '/var/www/node/importacion/api/csv_files/{$file}' INTO TABLE cuentas FIELDS TERMINATED BY '|'";
try {
$resp = $mysqli->query($sql);
$mysqli->close();
$respuesta = array(
"server" => $resp
);
}catch (Exception $e){
print_r($e->getMessage());
}
echo json_encode($respuesta);