PHP:使用DOMPDF自动将动态PDF保存到远程服务器

时间:2022-10-28 15:34:06

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.

我正在使用dompdf库来创建基于PDF的表格,我可以在线查看它,或者我可以将它下载到所选的用户文件夹中。

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.

但我想要做的是将它保存到远程服务器(我不需要它保存到用户PC),就像一个自动上传脚本,将创建该文件,然后将其上传到远程服务器,所以我然后可以在我的应用程序中使用它。

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.

有没有可能指向$ _FILES [“file”]脚本说如此获取创建pdf的php页面然后从那里上传它。

4 个解决方案

#1


15  

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.

你可以做下面的一件事,我正在为我的申请做。例如,首先在根目录下的服务器中创建一个文件夹。然后使用chmod命令将读写权限更改为该文件夹。

Then get all the code in $html string.

然后获取$ html字符串中的所有代码。

$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.

其中pdfReports是我为保存所有pdf而创建的文件夹。您可以更改为文件夹名称。

#2


0  

Quoted from PHP manual :

引自PHP手册:

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.

如果已启用fopen包装器,则URL可用作此函数的文件名。有关如何指定文件名的更多详细信息,请参见fopen()。有关各种包装器具有哪些功能的信息,使用说明以及它们可能提供的任何预定义变量的信息,请参阅支持的协议和包装器。

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

资料来源:http://php.net/manual/en/function.file-put-contents.php

#3


0  

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.

是否可以直接在服务器上创建PDF,如果需要,让客户端下载它?如果是这样,您可以使用wkhtmltppdf将任何HTML页面转换为服务器上的PDF并保存和/或将其传输到客户端。

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

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

#4


0  

Can't you use the FTP functions of PHP ?

你不能使用PHP的FTP功能吗?

#1


15  

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.

你可以做下面的一件事,我正在为我的申请做。例如,首先在根目录下的服务器中创建一个文件夹。然后使用chmod命令将读写权限更改为该文件夹。

Then get all the code in $html string.

然后获取$ html字符串中的所有代码。

$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.

其中pdfReports是我为保存所有pdf而创建的文件夹。您可以更改为文件夹名称。

#2


0  

Quoted from PHP manual :

引自PHP手册:

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.

如果已启用fopen包装器,则URL可用作此函数的文件名。有关如何指定文件名的更多详细信息,请参见fopen()。有关各种包装器具有哪些功能的信息,使用说明以及它们可能提供的任何预定义变量的信息,请参阅支持的协议和包装器。

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

资料来源:http://php.net/manual/en/function.file-put-contents.php

#3


0  

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.

是否可以直接在服务器上创建PDF,如果需要,让客户端下载它?如果是这样,您可以使用wkhtmltppdf将任何HTML页面转换为服务器上的PDF并保存和/或将其传输到客户端。

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

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

#4


0  

Can't you use the FTP functions of PHP ?

你不能使用PHP的FTP功能吗?