>  기사  >  백엔드 개발  >  (高分)为啥这段代码不能实现文件下载

(高分)为啥这段代码不能实现文件下载

WBOY
WBOY원래의
2016-06-13 11:42:59708검색

(高分)为什么这段代码不能实现文件下载
高分悬赏:
为什么我这段代码不能实现文件下载,在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);
}
?>

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.