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

Simon Davies picture Simon Davies · Feb 13, 2013 · Viewed 16.6k times · Source

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.

Answer

Venkata Krishna picture Venkata Krishna · Feb 13, 2013

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.