(高分)為什麼這段代碼不能實現檔案下載
高分懸賞:
為什麼我這段代碼不能實現檔案下載,在LINUX和WINDOWS下我都試過了。在WINDOWS下運行到OB_start();程式就沒運行下去了。
$root="D:/wamp/www/panjinli/downloadsouce";
if(is_dir($root))
{
$openHandle=opendir($root);
while(false!==($file=readdir($openHandle)))
{
if(!is_dir($root.$file))
{
echo "".$root.$file."
";
}
}
closedir($openHandle);
}else
{
echo "檔案夾不存在";
}
$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';
if($do=='down')
{
$file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : '';
$path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : '';
OB_start();
function DownLoad($info,$file)
{
OB_Clean();
if(!file_exists($info))
{
exit('Error:'.__LINE__.','.basename(__FILE__).'!');
}
$info=file_get_contents($info);
header('Content-Transfer-Encoding: binary');
header('Content-Type: application/force-download; name="'.$file.'"');
header('Content-Disposition: attachment; filename='.$file.'');
header('Cache-control: private');
header('Pragma: no-cache');
header('Expires: 0');
echo $info;
die();
}
DownLoad($path.$file,$file);
}
?>
分享到: 更多
------解決方案--------------------
DownLoad($path.$file,$file);
換成
DownLoad($path.'/'.$file,$file);
------解決方案--------------------
header('Content-Disposition: attachment; filename='.urlencode($file).'');