0

Wondering how I can store FPDF generated file from form fields in a variable or other for use in CURL request. I am able to upload a file via the file upload e.g input type="file" name="file" manually and post it with CURL but not with the automatically generated pdf file.

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
...
roshambo
  • 2,624
  • 6
  • 31
  • 54
  • Hi I have posted a new question following on from this. I have been able to send the pdf file to the API endpoint without storing file in my proposed curlfile idea - but the file is not opening properly. http://stackoverflow.com/questions/34645470/php-curl-file-post-not-opening-properly-in-api-endpoint – roshambo Jan 07 '16 at 00:40

1 Answers1

-1

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->Output('yourfilename.pdf','F');

If you want to save file at server directory:(make sure you have 777 writing permissions for that folder!):

$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/

  • Hi, thanks for the information. I can generate/save pdf file from form submission on my local machine/directory no problem. It is storing the file into something for later use for a CURL request. It should automatically POST after being generated. I am using this as a reference: http://stackoverflow.com/questions/4223977/send-file-via-curl-from-form-post-in-php. – roshambo Jan 06 '16 at 04:40