I am trying to download a file, say an image, to a client's computer in PHP.
download.php
<?php
$file = "path_to_file";
header('Content-Disposition: attachment; filename="'.basename($file).'"');
readfile($file);
exit;
?>
Using the code above works fine, as long as I open the PHP file "manually" in the browser. When using AJAX to execute the PHP code from a JS file (see below), however, it simply does nothing.
var request = $.ajax({
url: "download.php",
type: "post"
});
How could I fix this?
Thank you for your answers.
Aucun commentaire:
Enregistrer un commentaire