我正在尝试从 PHP 页面(Apache、LAMP)的 HTML 文件创建 PDF 奇怪的是,当我从命令行执行脚本时,它可以正常工作并按预期创建 PDF。但是,当我在浏览器中浏览该页面时,它什么也不做。我认为这是某个地方的权限问题,但我很难过!这是代码。(注意 ls 命令确实会在浏览器中产生输出,所以这不仅仅是 PHP 不允许执行 shell 命令的问题)
<?php
$htmlName = ("output2/alex" . time() . ".html");
$pdfName = ("output2/alex" . time() . ".pdf");
$html = "<html><body><h1>Hello, World!</h1></body></html>";
$fileHandle = fopen($htmlName, "w+");
fwrite($fileHandle, $html);
fclose($fileHandle);
$command= "htmldoc -t pdf --browserwidth 1000 --embedfonts --header ... --footer t./ --headfootsize 5.0 --fontsize 9 --bodyfont Arial --size letter --top 4 --bottom 25 --left 28 --right 30 --jpeg --webpage $options '$htmlName' -f '$pdfName'";
echo "OUTPUT: \r\n";
$X=passthru($command);
echo "TESTING LS:";
$y=passthru("ls -al");
if(file_exists($htmlName) && file_exists($pdfName)) {
echo "Success.";
} else {
echo "Sorry, it did not create a PDF";
}
?>
当我从命令行执行脚本时,它会产生预期的输出,并创建一个 PDF 文件,如下所示:
> php alextest.php
Zend OPcache requires Zend Engine API version 220131226.
The Zend Engine API version 220100525 which is installed, is outdated.
OUTPUT:
PAGES: 1
BYTES: 75403
TESTING LS:total 2036
drwxr-xr-x 9 ----- and so on...
当我在 Chrome 中浏览页面时,它只输出 LS 命令。
帮助!?