通过阅读codeigniter文档,我使用以下代码从我的服务器强制下载文件。Codeigniter Force下载文件
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阅读器中打开?错误? – 2013-02-12 15:16:34
是的..当我碰到我创建'download/32'的链接时,它只是打开链接,它是一个空白页面。 它是'下载/ $ file_id' .. – prakashchhetri 2013-02-12 15:18:15
.zip,.jpg,.txt,.gif所有工作,但不.pdf – prakashchhetri 2013-02-12 15:20:04