1
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 file download_file.php 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);
?>
Everything works correctly, the file is downloaded. But the goal is the file to be stored under the following name "BD Fugas Gespost.xls" and is being guarded as "ficheiro_xls%2FBD+Fugas+Gespost.xls". I’ve tried how it’s up to use the %20
to replace space, but it doesn’t work
I think your problem is in the line that you speak:
file=ficheiro_xls/BD%20Fugas%20Gespost.xls
and then read:$file = $_GET["file"];
. The problem is not in PHP, but in the instruction you give it. See if it is necessary to include thisficheiro_xml/
.– Fred Dutra
@Freddutra, file not required/
– pc_oc