0

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');

誰かが何が悪いのか知っているなら、私を助けてください。何時間もそれを続けてきました。ありがとう

4

0 に答える 0