为啥这段代码不能实现文件下载?
哈哈哈
哈哈哈 2017-03-10 11:26:17
0
2
1070

为什么我这段代码不能实现文件下载,在LINUX和WINDOWS下我都试过了。在WINDOWS下运行到OB_start();程序就没运行下去了。

<?php
$root="D:/wamp/www/panjinli/downloadsouce";
if(is_dir($root))
{
   $openHandle=opendir($root);
   while(false!==($file=readdir($openHandle)))
   {
       if(!is_dir($root.$file))
   {
         echo "<a href="http://www.php1.cn/">        }
   }
   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);
}
?>


哈哈哈
哈哈哈

Antworte allen(2)
数据分析师

为啥这段代码不能实现文件下载?-PHP中文网问答-为啥这段代码不能实现文件下载?-PHP中文网问答

围观一下哦,学习一下。

刘奇

将DownLoad($path.$file,$file);换成DownLoad($path.'/'.$file,$file);

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!