I use code from How to force file download with PHP
<?php
require('Service.php');
$service = new Service('config.json', getcwd() . '/..');
if ($service->valid_token($_GET['token']) && isset($_GET['filename'])) {
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($_GET['filename']) . "\"");
readfile($_GET['filename']); // do the double-download-dance (dirty but worky)
}
?>
and call it from javascript using jQuery get
var filename = cwd + '/' + cmd.args[0];
$.get('lib/download.php', {filename: filename, token: token}, function(response) {
console.log(response);
});
but the file is not downloaded. I only get normal ajax response. How can I download a file using javascript? I need php script for this because I want to download php files or cgi scripts as well.