【发布时间】:2012-08-07 16:16:32
【问题描述】:
我在使用 CodeIgniter 下载文件时遇到问题..
代码在单独的 php 文件中完美运行,但是当我将代码放入 CodeIgniter 时: 该文件将成功下载,但已损坏:(。
注意:我正在处理来自远程服务器的视频文件。
代码:
$file = fopen ($link, "r");
if (!$file) {
echo "<p align='center' style='color:#FF0101;'>Unable to open remote file :(, Please try again in a few minutes.</p>";
}else{
ob_clean();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Disposition: attachment; filename=zxc.3gp');
//header("Content-Transfer-Encoding: binary");
//header("Content-Length: ".$video_size);
while (!feof ($file)) {
$line = fgets ($file, 1024);
echo $line;
ob_flush();
flush();
}
fclose($file);
die();
}
我在新的 CodeIgniter 项目中尝试了这段代码:
public function index()
{
$link = 'http://mamprogr.net.tc/tmp/1.3gp';
$this->load->helper('download');
force_download('1.3gp',$link);
}
但不工作:(
【问题讨论】:
-
有什么问题?什么不工作?任何错误信息? What have you tried?
-
CodeIgniter Output Class 是罪魁祸首!请参阅 是的问题。
-
您是否使用 gzip 压缩输出?如果是这样,那是你的问题。如果启用了 gzip 压缩,则不能直接从控制器方法输出内容。您必须使用视图。
标签: php codeigniter