I’ve got the following file:
download.php
<?php
$filename = $_GET["filename"];
if ($filename) {
$path = "/svg_files/".$filnavn."";
header('Content-Transfer-Encoding: binary'); // For Gecko browsers mainly
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT');
header('Accept-Ranges: bytes'); // For download resume
header('Content-Length: ' . filesize($path)); // File size
header('Content-Encoding: none');
header('Content-Type: application/svg'); // Change this mime type if the file is not PDF
header('Content-Disposition: attachment; filename=' . $filename); // Make the browser display the Save As dialog
}
?>
It’s located in the svg_files folder. But when I run:
myweb.com/svg_files/download.php?filename=file.svg
I just get an empty file.
You’ll have to output the content of the file to the browser..
Use
readfileorfile_get_contentsandechoor something similar.As a sidenote: Be aware of so called directory traversal attacks. You might wanna take some precautions.
http://en.wikipedia.org/wiki/Directory_traversal_attack