PHP MySQL: Saving PDF to Database

后端 未结 2 1194
抹茶落季
抹茶落季 2020-12-18 12:54

I am generating PDFs with TCPDF, I want to save the generated pdf as blob in a MySQL db. What data should I save to the db? Code for PDF page



        
相关标签:
2条回答
  • 2020-12-18 13:26

    Output($name='example_001.pdf', $dest='I')

    the values of the $dest string (Destination where to send the document) can be:

    I: send the file inline to the browser (default). 
    D: send to the browser and force a file download with the name given by name.
    F: save to a local server file with the name given by name.
    S: return the document as a string (name is ignored).
    FI: equivalent to F + I option
    FD: equivalent to F + D option
    E: return the document as base64 mime multi-part email attachment (RFC 2045)
    

    hope that helps!

    0 讨论(0)
  • 2020-12-18 13:33

    The answer is right there, in your code:

    // Close and output PDF document
    // **This method has several options**, check the source code documentation for more information.
    $pdf->Output('example_001.pdf', 'I');
    

    From the documentation:

    Parameters: (...) string $dest Destination where to send the document. It can take one of the following values: (...) S: return the document as a string. name is ignored.

    So, change your code thus:

    $pdffilecontent = $pdf->Output('', 'S');
    

    and save that string to the database

    0 讨论(0)
提交回复
热议问题