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

时间:2013-12-16 16:18:57

标签: 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类的文件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()编写路径的方式是使用我最近学过的服务器文档根目录而不是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');

如果有人知道什么是错的,请帮助我,在那里待了好几个小时。感谢

0 个答案:

没有答案