我有一个网站,每个人都可以下载rar或pdf文件。
function download_file($download_url)
{
if( headers_sent())
die('Headers Sent');
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
if(file_exists($download_url))
{
$fsize = filesize($download_url);
$path_parts = pathinfo($download_url);
$ext = strtolower($path_parts["extension"]);
switch ($ext)
{
case "pdf": $ctype="application/pdf"; break;
//case "exe": $ctype="application/octet-stream"; break;
//case "zip": $ctype="application/zip"; break;
case "rar": $ctype="application/x-rar"; break;
//case "doc": $ctype="application/msword"; break;
//case "xls": $ctype="application/vnd.ms-excel"; break;
//case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
//case "gif": $ctype="image/gif"; break;
//case "png": $ctype="image/png"; break;
//case "jpeg":
//case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=\"".basename($download_url)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$fsize);
ob_clean();
flush();
readfile( $download_url );
}
else echo "<div class='alert-box notice'><i class='fa fa-exclamation-circle' aria-hidden='true'></i>
This file could not be loaded... Contact an <a href='help'>an agent</a>.</div>";
header( "refresh:3;url=myinventory");
}
问题在于有人下载..文件说&#34; archieve格式未知或损坏&#34;。
如何在我的下载系统中解决这个大问题? 我尝试了许多事情但是一样......