从子文件夹加载 dompdf
Loading dompdf from subfolder
我似乎无法定位 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');
这给出了以下输出:
Warning: file_get_contents(http://www.example.com/test.html): failed
to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in
/home/sites/www.example.com/web/wp-content/plugins/example/incl/dompdf.php
on line 40
Fatal error: Uncaught exception 'Dompdf\Exception' with message
'Requested HTML document contains no data.' in
/home/sites/www.example.com/web/wp-content/plugins/example/incl/dompdf/src/Frame/FrameTree.php:146
Stack trace: #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} thrown in
/home/sites/www.example.com/web/wp-content/plugins/example/incl/dompdf/src/Frame/FrameTree.php
on line 146
被调用的 test.html 存在并且可以被浏览器访问。如果我将 URL 替换为 Google 或 Yahoo 等其他内容,它也能正常工作。
我错过了什么,这是服务器配置问题吗?
我错了,代码有效。在开发服务器上有一个 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
删除它,它起作用了。必须是星期一。
我似乎无法定位 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');
这给出了以下输出:
Warning: file_get_contents(http://www.example.com/test.html): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/sites/www.example.com/web/wp-content/plugins/example/incl/dompdf.php on line 40
Fatal error: Uncaught exception 'Dompdf\Exception' with message 'Requested HTML document contains no data.' in /home/sites/www.example.com/web/wp-content/plugins/example/incl/dompdf/src/Frame/FrameTree.php:146 Stack trace: #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} thrown in /home/sites/www.example.com/web/wp-content/plugins/example/incl/dompdf/src/Frame/FrameTree.php on line 146
被调用的 test.html 存在并且可以被浏览器访问。如果我将 URL 替换为 Google 或 Yahoo 等其他内容,它也能正常工作。 我错过了什么,这是服务器配置问题吗?
我错了,代码有效。在开发服务器上有一个 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
删除它,它起作用了。必须是星期一。