从子文件夹加载dompdf

时间:2016-01-25 13:31:51

标签: php wordpress plugins dompdf

我似乎无法定位dompdf文件夹之外的文件,我发现我需要$dompdf->set_option('isRemoteEnabled', true); 设置以允许脚本处理网站上的其他页面,但仍然没有运气。到目前为止,这是我的代码;

$dompdf = new DOMPDF;
$dompdf->set_option( 'isRemoteEnabled', true );
$html = file_get_contents("http://www.example.com/test.html");
$dompdf->load_html($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$pdf = $dompdf->output();
$dompdf->stream('test');

这给出了以下输出:

  

警告:file_get_contents(http://www.example.com/test.html):失败   打开流:HTTP请求失败! HTTP / 1.1 403禁止进入   /home/sites/www.example.com/web/wp-content/plugins/example/incl/dompdf.php   在第40行

     

致命错误:带有消息的未捕获异常“Dompdf \ Exception”   “请求的HTML文档不包含任何数据。”在   /home/sites/www.example.com/web/wp-content/plugins/example/incl/dompdf/src/Frame/FrameTree.php:146   堆栈跟踪:#0   /home/sites/www.example.com/web/wp-content/plugins/example/incl/dompdf/src/Dompdf.php(572):   Dompdf \ Frame \ FrameTree-> build_tree()#1   /home/sites/www.example.com/web/wp-content/plugins/example/incl/dompdf/src/Dompdf.php(722):   Dompdf \ Dompdf-> processHtml()#2   /home/sites/www.example.com/web/wp-content/plugins/example/incl/dompdf.php(43):   Dompdf \ Dompdf-> render()#3 {main}抛出   /home/sites/www.example.com/web/wp-content/plugins/example/incl/dompdf/src/Frame/FrameTree.php   第146行

调用的test.html存在且可由浏览器访问。如果我用谷歌或雅虎之类的东西替换该URL,它也可以工作。 我缺少什么,这是服务器配置问题吗?

1 个答案:

答案 0 :(得分:0)

我错了,代码正常运行。在开发服务器上有一个htaccess阻塞请求:

SetEnvIfNoCase User-Agent ^$ keep_out
SetEnvIfNoCase User-Agent (pycurl|casper|cmsworldmap|diavol|dotbot) keep_out
SetEnvIfNoCase User-Agent (flicky|ia_archiver|kmccrew) keep_out
SetEnvIfNoCase User-Agent (purebot|comodo|feedfinder|planetwork) keep_out
Order Allow,Deny
Allow from all
Deny from env=keep_out

删除了它,并且它有效。必须是星期一。

相关问题