I have the following button that goes to a file:
<a href="download_file.php?file=ficheiro_xls/BD%20Fugas%20Gespost.xls">Download XLS</a>
In the download_file.php file I have the following:
<?php
header("Content-Type: application/octet-stream");
$file = $_GET["file"];
header("Content-Disposition: attachment; filename=" . urlencode($file));
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp))
{
echo fread($fp, 65536);
flush(); // this is essential for large downloads
}
fclose($fp);
?>
It works correctly, the file is unloaded. But the goal is to save the file with the following name " BD Trails Gespost.xls " and is being saved as " xls% 2FBD + Trails + Gespost.xls " . I've tried as above to use %20
to replace space, but it does not work.