I have been investigating for a few hours now, and I have not been able to find much useful information.
With which I refer here to see if I can find help.
-
I have a form, that I work with jQuery, with what I have stored all the variables and data there.
-
I want to try to do the following: when sending the form, generate a CSV file that is saved in any folder of the server. With a specific format.
* ¨ I have nothing done, since I have tried to investigate and I have not found much information.
I would appreciate help to know if I could do this in PHP and jQuery.
EDITING WHAT I HAVE TRIED
I created a PHP file:
<?php
$cod_cliente = ($_POST['cod_cliente']);
$optica = ($_POST['optica']);
$fecha = ($_POST['fecha']);
$tipo = ($_POST['tipo']);
$lista = array (
array('Codigo Cliente', 'Cliente', 'Fecha', 'Tipo'),
array('$cod_cliente', '$optica', '$fecha', '$tipo'),
);
$fp = fopen('fichero.csv', 'w');
foreach ($lista as $campos) {
fputcsv($fp, $campos);
}
fclose($fp);
?>
And within the jQuery of sending the order, this ajax:
$.ajax({
type: 'POST',
url: 'php/generarCsv.php',
data: {'cod_cliente': cod_cliente,
'optica': optica,
'fecha': fecha,
'tipo': tipoCi}
})
.done(function(listas_rep){
alert('CSV Generado con exito');
})
.fail(function(){
alert('Error al crear el archivo CSV')
})
I must say, that above that ajax, I have another, which sends me the order to the database. I do not know if it will conflict.
This, right now, does not do me absolutely nothing.