该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
求助~今天写了个文件下载的程序,从浏览器控制台看到接收到了服务器返回的数据,但是不弹出来下载框怎么破?
代码如下:
public function downfileAction(){
$fileID = $this->getRequest()->getParam('fileID');
$file_name = iconv("utf-8","gb2312",substr($fileID, strripos ($fileID, "/") + 1));
$file_path = $fileID;
if(!file_exists($file_path)){
echo "文件不存在";
exit();
}
$fp = fopen($file_path, "r");
$file_size = filesize($file_path);
file_put_contents("D:/XMAPP/htdocs/disk/mylog.log",
$file_size."\r\n", FILE_APPEND);
header("Content-type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Accept-Length: $file_size");
header('Content-Transfer-Encoding: binary');
header("Content-Disposition: attachment; filename=".$file_name);
//回送数据
$buffer=4096;
$file_count=0;
while(!feof($fp) && ($file_size - $file_count > 0)){
$file_data = fread($fp, $buffer);
$file_count += $buffer;
echo $file_data;
}
fclose($fp);
exit();
}