+ -
当前位置:首页 → 问答吧 → zend 文件下载问题

zend 文件下载问题

时间:2011-06-18

来源:互联网

遇到个问题,要实现一个文件下载功能,如果代码不放在zend里,单独一个php文件运行,没有什么问题。
  但是放在zend里后,文件是能找到,也能下载,但是下载下来的文件格式好像被破坏了,打不开。
  不光是jpg,其它格式rar、exe的我也都试过,下载下来后都不行。
  有没有知道原因的,请教下。 把代码列下来了,代码应该没问题,就是php manual里的,应该是zend里哪影响了。
PHP code

<?php
$file = 'downloading.jpg';
if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
?>

作者: aidiweili   发布时间: 2011-06-18

自己解决,不是zend原因,非常非常奇怪的问题,不过搞定了

作者: aidiweili   发布时间: 2011-06-18