简体   繁体   English

将FPDF输出存储到变量或新的CURLFILE中

[英]Storing FPDF output into variable or new CURLFILE

Wondering how I can store FPDF generated file from form fields in a variable or other for use in CURL request. 想知道如何将来自表单字段的FPDF生成的文件存储在变量或其他变量中,以便在CURL请求中使用。 I am able to upload a file via the file upload eg input type="file" name="file" manually and post it with CURL but not with the automatically generated pdf file. 我能够通过文件上传来上传文件,例如手动输入type =“ file” name =“ file”并使用CURL发布,但不能使用自动生成的pdf文件发布。

Is this possible? 这可能吗? See below code: 请参阅以下代码:

$noteTitle = (isset($_POST['noteTitle']) ? $_POST['noteTitle'] : null);
$noteBody = (isset($_POST['noteBody']) ? $_POST['noteBody'] : null);

//FPDF
require("fpdf/fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont("Arial", "B", 16);
$pdf->Cell(0,100, "Note Title: {$noteTitle} \n", 1, 0, 'C');
$pdf->Cell(0,100, "Note Body: {$noteBody}", 1, 0, 'C');
$filename="test.pdf";
$pdf->output($filename,'f');

$cfile = new CURLFILE($_FILES[$pdf]['tmp_name'], $_FILES[$pdf]['type'], $_FILES[$pdf]['name']);

//Post to curl
$data = array();
$data['FILE_ATTACHMENTS'] = $cfile;
//curl code etc
...

First you need to save dynamically generated at server directory then you can use for the upload or any other purpose like send as attachment email. 首先,您需要将动态生成的文件保存在服务器目录中,然后可以用于上载或任何其他目的,例如作为附件电子邮件发送。

For Saving the PDF as a file use below method: 要将PDF保存为文件,请使用以下方法:

$pdf->Output('yourfilename.pdf','F'); $ pdf-> Output('yourfilename.pdf','F');

If you want to save file at server directory:(make sure you have 777 writing permissions for that folder!): 如果要将文件保存在服务器目录中:(请确保您具有该文件夹的777写入权限!):

$pdf->Output('directory/yourfilename.pdf','F'); $ pdf-> Output('directory / yourfilename.pdf','F');

For more details you can visit tutorial: http://www.phpmysqlquery.com/fpdf-output-methods-for-pdf-files-in-php/ 有关更多详细信息,请访问教程: http : //www.phpmysqlquery.com/fpdf-output-methods-for-pdf-files-in-php/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM