Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/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_Pdf_Download - Fatal编程技术网

Codeigniter pdf文件下载时出错

Codeigniter pdf文件下载时出错,codeigniter,pdf,download,Codeigniter,Pdf,Download,您好,我的网站上有一些pdf文件,用户可以下载,但问题是,当我们下载这些pdf文件并尝试打开pdf时,我遇到了一个错误“打开文档时出错。文件已损坏,无法修复”,但在我的本地系统中,此操作正常。 请引导我,这是我的密码 function download_pdf($parameters) { $final_link = "$parameters"; $path = strtolower($final_link); $file = "$path"; if

您好,我的网站上有一些pdf文件,用户可以下载,但问题是,当我们下载这些pdf文件并尝试打开pdf时,我遇到了一个错误“打开文档时出错。文件已损坏,无法修复”,但在我的本地系统中,此操作正常。 请引导我,这是我的密码

function download_pdf($parameters)
{

    $final_link = "$parameters";
    $path = strtolower($final_link);
    $file = "$path";

        if (file_exists($file)) {
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment;       filename='.basename($file));
            header('Content-Transfer-Encoding: binary');
            header('Expires: 0');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            header('Content-Length: ' . filesize($file));
            ob_clean();
            flush();
            readfile($file);
            exit;
        }
        else
        {
            //echo "file do not exist";
            redirect('site/file_does_not_exist');
            //$data['main_content'] = 'not_found';
            //$this->load->view('includes/template',$data);
        }
}

请尝试使用此选项:

...
header('Content-Type: application/pdf');
...

并确保文件名的扩展名为“.pdf”

application/pdf: Portable Document Format