PHP:使用DOMPDF自动将动态PDF保存到远程服务器 [英] PHP: Automatically Saving a dynamic PDF to the remote server using DOMPDF
问题描述
我正在使用dompdf库创建基于表格的PDF,可以在线查看它,也可以将其下载到用户选择的文件夹中。
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.
但是我想做的是将其保存到远程服务器(我不需要将其保存到用户PC),就像自动上传脚本可以创建文件然后将其上传到远程服务器一样,所以我可以然后在我的应用程序中使用它。
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.
是否可以指向$ _FILES [ file]脚本说,以便获取创建pdf的php页面,然后从那里上传它。
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.
推荐答案
您可以执行以下操作,例如我为应用程序所做的操作。例如,首先在服务器的根目录下创建一个文件夹。然后使用chmod命令更改对该文件夹的读写权限。
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.
然后获取 $ html
字符串中的所有代码。
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);
其中 pdfReports
是我创建的文件夹保存所有PDF文件。您可以更改为文件夹名称。
Where pdfReports
is the folder which i created to save all the pdf's. You can change to your folder name.
这篇关于PHP:使用DOMPDF自动将动态PDF保存到远程服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!