Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从codeigniter中的服务器下载pdf文件_Codeigniter_File_Pdf_Download - Fatal编程技术网

无法从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

我在控制器中使用以下代码下载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";}

内容处置
中的名称更改为仅文件名,而不是完整路径

以下是我在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
来自哪里?