Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 317
Simon Davies Avatar asked Feb 13 '13 10:02

Simon Davies


1 Answers

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.

like image 186
Venkata Krishna Avatar answered Oct 19 '22 04:10

Venkata Krishna