I have a problem with a function that is supposed to download. Why are empty files being downloaded? Where am I going wrong? Thank you all.
I pass the name of the file I need to download to the function.
function downloadAttachmentKb($filesDownload)
{
if (empty($filesDownload)){
return false;
}
set_time_limit(0);
$DownloadDir = "./files/kbfiles/".$filesDownload ;
$DownloadFiles = basename( $filesDownload);
$DovnloadSize = filesize( $DownloadDir);
if (!file_exists($DownloadDir) && !is_writable($DownloadDir)){
die("errore");
}
$MimeFile = mime_content_type($DownloadDir);
if ($MimeFile === false){
header("Content-Type: application/force-download");
}else{
header(header: "Content-Type:".$MimeFile."");
}
if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")){
header("Content-Disposition: inline ; filename="". $DownloadFiles.""");
} else{
header(header: "Content-Disposition: attachment; filename="". $DownloadFiles .""");
}
header(header: "Content-Length: ". filesize($DownloadDir));
header("Content-Description: File Transfer");
header("Content-Transfer-Encoding: binary");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: public");
ob_clean();
flush();
echo file_get_contents($DownloadDir);
}
?>