无法从codeigniter中的服务器下载pdf文件
我在控制器中使用以下代码下载pdf文件,这些文件存储在codeigniter应用程序文件夹中的文件夹中。 在查看页面中,我有一个按钮,单击它,它会重定向到该控制器,然后下载文件。它下载空白页(pdf)。 期待任何建议无法从codeigniter中的服务器下载pdf文件,codeigniter,file,pdf,download,Codeigniter,File,Pdf,Download,我在控制器中使用以下代码下载pdf文件,这些文件存储在codeigniter应用程序文件夹中的文件夹中。 在查看页面中,我有一个按钮,单击它,它会重定向到该控制器,然后下载文件。它下载空白页(pdf)。 期待任何建议 $filePath = APPPATH.'invoice/'."Let's Sunday#".$this->uri->segment(4).".pdf"; if(!empty($filePath) && file_exists($fil
$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";}
将
内容处置
中的名称更改为仅文件名,而不是完整路径以下是我在CodeIgniter应用程序的下载部分中看到的内容:
if (file_exists($filePath)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($filePath).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filePath));
readfile($filePath);
flush();
exit;
}
不同之处在于标题的顺序(这可能无关紧要)、包含expires和pragma标题以及使用完整basename的内容配置
该PDF文件名的命名约定可能会导致一个问题…需要测试其他内容。您从哪里获得$pdfFilePath
?此外,在文件大小($file)
上,$file
来自哪里?