Buon pomeriggio.
Ho una funzione che invia due date ad un file scarica.php.
Questo scarica.php dovrebbe anche eseguire il download del file.csv, ma non lo fa, perché ovviamente faccio un errore, dove?E come posso risolvere?
codice:
if (confirm("Procedi con il download del file?")){
$.ajax({
type : "POST",
url : "scarica.php",
data : "rCerca=" + d1 + "&rCercaAl=" + d2,
dataType: "html",
success: function(html){
//$("#ddl").html(html);
window.location.href = "scarica.php";
//return;
},
error: function(html){
alert('error!');
//$("#csv").html(html);
}
});
}
else{
return;
}
Dentro scarica.php
codice:
$file = "csv/report_segnalazioni_".str_replace("/","",$_POST['rCerca'])."_".str_replace("/","",$_POST['rCercaAl']).".csv";
echo $file;
if (!file_exists($file))
{
// se non esiste stampo un errore
echo "Il file non esiste!".$file;
}else{
$filedimension = filesize($file);
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=$file");
header("Content-Description: Download file");
header("Content-Length: $filedimension");
readfile($file);
}
Il tutto funziona se non invio alcun valore per post.
Mi aiutate per favore?
Grazie