<?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;
}
?>
<p>Downloading file...</p> [[download]]
the snippet has to return TRUE regardless of the if/else statement. i would use try and catch, so that you can post any errors to the modx reportingMy snippet returns TRUE after the readfile()... but I have solve this problem by using a external script and then I make a link directly to the php script.