Кемеровские программисты php общаются здесь
Anonymous
Функция PHP, которая загружает пустые файлы [закрыто]
Сообщение
Anonymous » 25 июл 2025, 12:18
У меня есть проблема с функцией, которая должна загрузить. Почему пустые файлы загружаются? Куда я ошибаюсь? Спасибо всем.
Код: Выделить всё
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);
}
?>
Я думаю, что проблема в заголовках, так как я попробовал функцию в другом файле, и она там работает.
Подробнее здесь:
https://stackoverflow.com/questions/797 ... mpty-files
1753435107
Anonymous
У меня есть проблема с функцией, которая должна загрузить. Почему пустые файлы загружаются? Куда я ошибаюсь? Спасибо всем.[code]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); } ?> [/code] Я думаю, что проблема в заголовках, так как я попробовал функцию в другом файле, и она там работает. Подробнее здесь: [url]https://stackoverflow.com/questions/79709965/php-function-that-downloads-empty-files[/url]