On my website I'ld like to add a link to download a file.
The problem is that :
- the file is saved with an id and not the full name (stored in a database). I want to change it before sending it (don't know yet how to do that).
- I've to check that the user has the right permissions to access this file.
function getFile(id) {
var xhr_download = getXMLHttpRequest();
xhr_download.onreadystatechange = function() {
if (xhr_download.readyState == 4 && (xhr_download.status == 200 || xhr_download.status == 0)) {
alert(xhr_download.responseText);
$('#loader').hide();
} else if (xhr_download.readyState < 4) {
$('#loader').show();
}
};
xhr_download.open("GET", "proceed_files.php?action=getfile&id="+id, true);
xhr_download.send(null);
}
<?php
// ...
try {
header("Content-disposition:filename='".$path."'");
header("Content-type:application/octetstream");
echo file_exists($path);
}
catch (Exception $e) { echo $e->getMessage(); }
?>
return me "1" but nothing happensif I put this piece of code in a php file and call it directly it works
So I guess the problem is with the ajax request
Thank you















