I have created a snippet to download a file (and in future I want to log into a database).
The problem is the file is not downloaded but the content is display into the browser !!
<?php
$file = $_GET['file']; //Get the file from URL variable
$file_path = "assets/files/".$file; //Set the file path w.r.t the download.php... It may be different for u
if (file_exists($file_path) && ($file != '') && (substr($file,1,1)!='.') && (substr($file,1,1)!='/'))
{
$size = filesize($file_path);
header("Content-Type: application/force-download; name=\"" . basename($file_path) . "\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $size");
header("Content-Disposition: attachment; filename=\"" . basename($file_path) . "\"");
header("Expires: 0");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
flush();
readfile($file_path);
echo "$file successfully downloaded<br>";
return true;
}
else
{
echo "Sorry, the file ".$file." does not exist!<br>";
return false;
}
?>
and the page called "downloadingfile" is
<p>Downloading file...</p>
[[download]]
The URL is
http://www.mydomain.com/en/downloadingfile?file=xe/app_setup.exe
Thank for you help
Franck