Good Day I made a folder outside of my public_html to hold sensitive client data. I am having no issues uploading to this folder, but I am a bit confused as to how to initiate a download once the ajax call succeeds (using jQuery)
My php script to access the file is below
$file = basename($_GET['link']);
$file = '../secure-uploads/'.$file;
if(!file_exists($file)){ // file does not exist
echo "cant find it";
die('file not found');
} else {
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
// read the file from disk
readfile($file);
}
My ajax call is as follows
$.ajax({
url: "file-download.php?callback=?",
type: "GET",
crossDomain: true,
data: {link: link},
success: function (data, status) {
// I would like a zipped file to start downloading here
}
});
Once the ajax is a success I would like to have it zipped and automatically download without any extra links if possible. If I console.log the data it is the actual file data instead of a zipped dowload.
Anyone know how to achieve this?