PHP: Automatically Saving a dynamic PDF to the remote server using DOMPDF

17,750

You can do one thing like below which i am doing for my application. First create a folder in your server under the root directory for example. Then change read write permissions to that folder using chmod command.

Then get all the code in $html string.

$dompdf->load_html($html);    
$dompdf->render();
$pdf = $dompdf->output();
$file_location = $_SERVER['DOCUMENT_ROOT']."app_folder_name/pdfReports/".$pdf_name.".pdf";
file_put_contents($file_location,$pdf); 

Where pdfReports is the folder which i created to save all the pdf's. You can change to your folder name.

Share:
17,750
Simon Davies
Author by

Simon Davies

Developer of web but not the spider kind. Also a rugby ref on the weekends...

Updated on June 13, 2022

Comments

  • Simon Davies
    Simon Davies almost 2 years

    I am using the dompdf library to create my table based PDF and I can view it online or I can have it download to the users folder of choice.

    But what I would like to do is have it save it to the remote server( i dont need it to be save to the users PC), like an automatically upload script that would create the file then upload it to the remote server, so i can then use it within my application later on.

    is it possible to point the $_FILES["file"] script say so fetch the php page that creates the pdf and it then uploads it from there.

  • Simon Davies
    Simon Davies about 11 years
    Thanks for this the file_put_contents has done the trick, i works on my simple page now to get it to work on my more complicated dynamic page, but thanks also thanks to Stephan, kufudo and Vincent Kelleher
  • Simon Davies
    Simon Davies about 11 years
    i just need to create one page but the table will be long, but looking into using PHPExcel to do the heavy work then using dompdf to convert, which i am doing now, will just need to implement the same fiel upload code to it and it should all be done.
  • Venkata Krishna
    Venkata Krishna about 11 years
    are you free to talk for 5 minutes
  • Simon Davies
    Simon Davies about 11 years