1

I'm attempting to use either mPDF or TCPDF, whichever is easier, to generate a PDF and then send it somewhere using FTP.

I cannot figure out how to assign a PDF to a variable so that I can then save the PDF as a file across FTP.

Here's an example of what I'm trying to do that doesn't work:

include("../mpdf60/mpdf.php");

$mpdf = new mPDF();
$mpdf->WriteHTML('<p>Hello World!</p>');
$generatedPDF = $mpdf->Output('', 'S');

// ...connect to ftp...

if (ftp_put($conn_id, 'test.pdf', $generatedPDF, FTP_BINARY)) { 
    $debug['ftp_FILECREATEsuccess'] = 'true';
} else { 
    $debug['ftp_FILECREATEsuccess'] = 'false';
} 

$debug:

["ftp_FILECREATEsuccess": false]

Note: If there are better php class systems for doing what I'm trying to do, please let me know.

Frank Minyon
  • 126
  • 10
  • the answer is here: https://mpdf.github.io/reference/mpdf-functions/output.html –  Apr 26 '17 at 21:20
  • @nogad I attempted to use this same documentation, but it does not provide me with how to send the file across a FTP connection. I have tried to include the `chunk_split(base64_encode($generatedPDF));` step but it still results in failure. – Frank Minyon Apr 26 '17 at 21:37
  • you try to send "test.pdf" but havent created "test.pdf" –  Apr 26 '17 at 21:39
  • @nogad the `test.pdf` should only be the name of the file once it is saved on the FTP server. The PDF object/data being put on to the FTP server is my variable `$generatedPDF`. I need my `$generatedPDF` variable to contain an FTP-friendly PDF object. – Frank Minyon Apr 26 '17 at 21:45
  • @FrankMinyon check [this answer](http://stackoverflow.com/a/43539323/2734189) for a way to create the file on the FTP server without creating a file locally. – Don't Panic Apr 26 '17 at 21:46
  • @Don'tPanic I attempted to use `file_put_contents('ftp://user:pass@host/test.pdf', $generatedPDF);` using various parameters on `$mpdf->Output()` but I was not successful in creating a file. I believe the problems lies in the data that my `$generatedPDF` variable holds. Although, I do not know how to correct the problem still. **Edit**: I attempted `$mpdf->Output('ftp://user:pass@host/test.pdf', 'F')` and it did not work either. – Frank Minyon Apr 26 '17 at 21:57
  • I would think that just outputting to a string like you have it in your question should work. I would suggest first verifying that the FTP transfer works by testing it with a simple string rather than the PDF output so you can rule that out as a possible cause. (I don't know, you may have already done that.) – Don't Panic Apr 26 '17 at 22:05
  • Could you try to add an extra forward slash to the url? i.e. `'ftp://user:pass@host//path/to/test.pdf'` – Philipp Apr 26 '17 at 22:10
  • @Don'tPanic I confirmed my FTP is working with basic `.txt` files and `.jpg` files. – Frank Minyon Apr 26 '17 at 22:14
  • @Philipp I attempted the second slash and it did not work. – Frank Minyon Apr 26 '17 at 22:14
  • 1
    Possible duplicate of [Transfer in-memory data to FTP server without using intermediate file](http://stackoverflow.com/q/27103587/850848#43539323) – Martin Prikryl Apr 27 '17 at 06:11

0 Answers0