PHP: Automatically Saving a dynamic PDF to the rem

2020-06-18 03:09发布

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.

4条回答
男人必须洒脱
2楼-- · 2020-06-18 03:32

Quoted from PHP manual :

A URL can be used as a filename with this function if the fopen wrappers have been enabled.See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.

Source: http://php.net/manual/en/function.file-put-contents.php

查看更多
走好不送
3楼-- · 2020-06-18 03:39

Is it feasible to create the PDF directly on the server instead, and let the client download it if he needs it? If so, you could use wkhtmltppdf to convert any HTML page into a PDF on the server and save it and/or stream it to the client.

http://code.google.com/p/wkhtmltopdf/

查看更多
ゆ 、 Hurt°
4楼-- · 2020-06-18 03:41

Can't you use the FTP functions of PHP ?

查看更多
乱世女痞
5楼-- · 2020-06-18 03:56

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.

查看更多
登录 后发表回答