【发布时间】:2013-01-27 22:38:50
【问题描述】:
通过阅读 Codeigniter 文档,我正在使用以下代码强制从我的服务器下载文件。
function download($file_id){
$file = $this->uploadmodel->getById($file_id); //getting all the file details
//for $file_id (all details are stored in DB)
$data = file_get_contents($file->full_path); // Read the file's contents
$name = $file->file_name;;
force_download($name, $data);
}
代码是图像的工作文件,但是当它附带 PDF 文件的情况下,它不起作用。我没有针对所有文件扩展名测试它,但由于它不适用于 PDF,它可能不适用于其他各种文件类型。 有什么解决办法吗?
【问题讨论】:
-
不工作怎么办?不下载?无法在 PDF 阅读器中打开?错误?
-
是的..当我点击我创建的链接
download/32时,它只是打开了链接,它是一个空白页面。它是download/$file_id.. -
.zip、.jpg、.txt、.gif 都可以,但 .pdf 不行
-
检查您的服务器的错误日志或在 app 文件夹中名为 error_log 的文件中,您可能会在那里找到一些有用的信息。如果两者都没有帮助,请尝试使用其他浏览器或尝试清除当前浏览器的缓存。
-
当你尝试下载 pdf 文件时,你能打印出你得到 $file 的数组吗..
标签: php codeigniter