PHP
·
发表于 5年以前
·
阅读量:8297
PS:Õa¶Î´uÂeÔÚwinϵͳÏÂÅÜûÓÐÎÊÌa,*a¸çÇײa¿ÉÓÃ.Èç¹uÓõÄÊÇlinux»oÊÇÆaËuϵͳ,ÒªÒªÖiλ×ÔÐвaÊÔÏÂÀ².
$filename = "./".$_REQUEST['name']; //ÕaÀiÊÇ*a¸ç¾ßÌaÂ*¾¶,Ö»Òª$filenameÊÇËuÒªÏÂÔØÎļþµÄÍeÕuÂ*¾¶¾Í¿ÉÒÔ.
if (!is_file($filename)) {//¼i²aÎļþÊÇ*ñ´aeÔÚ.
die('ÏÂÔصÄÎļþºÃÏñ¸uTMË˽±¼À²!');
}
$filepath = str_replace('\\', '/', realpath($filename));
$filesize = filesize($filepath);
$filename = substr(strrchr('/'.$filepath, '/'), 1);
$extension = strtolower(substr(strrchr($filepath, '.'), 1));
// use this unless you want to find the mime type based on extension,Îļþºo׺¸ñʽ,²»½aÊÍ.
$mime = array('application/octet-stream');
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.sprintf('%d', $filesize));
header('Expires: 0');
// check for IE only headers,¿ÓµuµÄIE¼i²a,Äa¶®µÄ.
if (isset($_SERVER['HTTP_USER_AGENT']) &&((strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)))
{
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
}
else
{
header('Pragma: no-cache');
}
$handle = fopen($filepath, 'rb');
fpassthru($handle);
fclose($handle);
Õa¸o´uÂeÊÇa¸ç´Ó¹uÍaµÄÒ»¸oÕ¾µaÉÏÕÒµ½µÄ,Çײa¿ÉÓÃ.¶ÈÄi³oÀ´µÄ½a¹u,Äa¶®µÄ.Òo´ËÔÚ²(C)¿ÍÉϹ²Ïi³oÀ´,Ï£Íu¶Ô´o¼ÒÓÐÓÃ.¹uÍaµÄÕ¾,µØÖÍuÁË,ûÓаi¨Å³o,Ài½aÏÂ.×iºo,ÑÏËaµÄÉuÃ÷ÏÂ:Õa¸o´uÂe²»ÊÇÎÒдµÄ,ÊÇתÔصÄ.