Php 无法在服务器上保存pdf文件或加载模板-FPDF/CodeIgniter

Php 无法在服务器上保存pdf文件或加载模板-FPDF/CodeIgniter,php,codeigniter,pdf,fpdf,fpdi,Php,Codeigniter,Pdf,Fpdf,Fpdi,我正在使用FPDF/FPDI创建/编辑/存储pdf文档。我在我的本地服务器(wamp)上试过,一切都很好;我可以上传模板,使用Output()将pdf保存到正确的文件夹中 但是当我将代码上传到服务器时,我得到了一个FPDF错误,上面写着: FPDF error: Cannot open /home/users/x/y/x/public_html/zamzamtravel/index.php/resources/pdf_templates/a_template.pdf ! 我发现错误是由FPDI

我正在使用FPDF/FPDI创建/编辑/存储pdf文档。我在我的本地服务器(wamp)上试过,一切都很好;我可以上传模板,使用Output()将pdf保存到正确的文件夹中

但是当我将代码上传到服务器时,我得到了一个FPDF错误,上面写着:

FPDF error: Cannot open /home/users/x/y/x/public_html/zamzamtravel/index.php/resources/pdf_templates/a_template.pdf !
我发现错误是由FPDI类的pdf_parser.php文件生成的,具体来说:

function pdf_parser($filename) {
            $this->filename = $filename;

            $this->f = @fopen($this->filename, 'rb');
           //error is this
            if (!$this->f)
                $this->error(sprintf('Cannot open %s !', $filename));

            $this->getPDFVersion();

            $this->c = new pdf_context($this->f);

            // Read xref-Data
            $this->xref = array();
            $this->pdf_read_xref($this->xref, $this->pdf_find_xref());

            // Check for Encryption
            $this->getEncryption();

            // Read root
            $this->pdf_read_root();
        }
我为setSourceFile()和Output()编写路径的方法是使用我最近学到的servers文档根,而不是HTTP路径。我还将模板和生成的pdf文件的文件/文件夹权限设置为775

如何写入和保存pdf文件:

$pdf = new FPDI('P','mm','A4');
        // add a page
        $pdf->AddPage();
        // set the sourcefile
        $pdf->setSourceFile($_SERVER['DOCUMENT_ROOT'] . '/myfolder/index.php/resources/pdf_templates/a_template.pdf');
        // import page 1
        $tplIdx = $pdf->importPage(1);

        $pdf->useTemplate($tplIdx, 1, 1, 210);
        // now write some text above the imported page
        $pdf->SetFont('Arial');
        $pdf->SetTextColor(0,0,0);

        // Write the posted variables somewhere in the document
        //write a bunch of stuff...

        // Output. Make the file name the ID of the person returned from database?
        $pdf->Output($_SERVER['DOCUMENT_ROOT'] . '/myfolder/index.php/resources/visa_application_forms/'. $data['full_name'] . "_" . $data['customer_id'] . '.pdf', 'F');

如果有人知道出了什么问题,请帮我解决,已经做了好几个小时了。谢谢

在$\u服务器['DOCUMENT\u ROOT']和'myfolder'之间有什么东西吗?我从/resources之前的路径中删除了所有内容,它可以正常工作。我想这并不像我想象的那么复杂。经验教训:自下而上:pyu可以使用codeigniter常量在每个服务器设置中获得正确的路径:BASEPATH、APPPATH、SYSDIR等。