【发布时间】:2018-01-19 11:54:50
【问题描述】:
我在我的控制器中使用以下代码下载 pdf 文件,这些文件存储在 codeigniter 的应用程序文件夹内的文件夹中。 在视图页面中,我有一个按钮,单击它后,它会重定向到此控制器,然后下载文件。它下载空白页(pdf)。 期待任何建议。
$filePath = APPPATH.'invoice/'."Let's Sunday#".$this->uri->segment(4).".pdf";
if(!empty($filePath) && file_exists($filePath)){
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" .$filePath);
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($filePath));
flush();
$fp = fopen($filePath, "r");
while (!feof($fp))
{
echo fread($fp, 65536);
flush();
}
fclose($fp); }else{echo "file does not exist";}
【问题讨论】:
-
你从哪里得到
$pdfFilePath? -
还有,
filesize($file)上的$file来自哪里?
标签: codeigniter file pdf download