phantomsjs 适用于命令但不适用于 exec() PHP
phantomsjs works on command but not with exec() PHP
我正在使用 Phantomjs,但效果不佳。我正在使用此命令从我的网页生成 PDF:
/var/www/html/hor/js/phantomjs /var/www/html/hor/js/_generate.js 1234
它运行良好(它没有找到 UI-kit js 文件,我还没有考虑这个问题)并且我的 PDF 目录中有我的 PDF。但是对于我的 PHP 文件,我什么都没有。
命令或 PHP 都使用 print_r() 给出以下错误代码:
TypeError: 'undefined' is not a valid argument for 'in' (evaluating
'"default"in t')
http://localhost/js/uikit.min.js:3
http://localhost/js/uikit.min.js:3
http://localhost/js/uikit.min.js:3
(所以在这两种情况下脚本都已启动)
我的 PHP 脚本:
<?php
$token = $_GET['token'];
$simul_mail = $_GET['simulmail'];
$cmd = ' /var/www/html/hor/js/phantomjs';
$cmd.= ' /var/www/html/hor/js/_generate.js';
$cmd.= ' '.$token;
if(isset($_GET['simulmail'])&&isset($_GET['token'])){
exec($cmd, $output);
}
print_r( $output );
?>
我的 _generate.js 文件由 phantomJS 执行:
fs = require('fs');
system = require('system');
token = system.args[1];
if(token!=null && token!=""){
fs.changeWorkingDirectory('/var/www/html/hor/pdf/');
var page = new WebPage();
var pagename = "PDF_"+token+".pdf";
page.open('http://localhost/_template-mail.php?v='+token, function (status) {
page.render(pagename);
phantom.exit();
});
}
else{
phantom.exit();
}
我能做什么?
遇到同样问题的,是关于权限的问题
Apache 没有写入我的 PDF 文件夹的权限。
带有 exec() 的 PhantomJS 使用 PHP 的权限,它正在使用 Apache 的权限。
如果 Apache 是该文件夹的所有者,则效果很好!
--> sudo chown <your username>:<your usergroup> -R <path to>/folder
sudo chown apache -R /var/www/html/hor/pdf
我正在使用 Phantomjs,但效果不佳。我正在使用此命令从我的网页生成 PDF:
/var/www/html/hor/js/phantomjs /var/www/html/hor/js/_generate.js 1234
它运行良好(它没有找到 UI-kit js 文件,我还没有考虑这个问题)并且我的 PDF 目录中有我的 PDF。但是对于我的 PHP 文件,我什么都没有。
命令或 PHP 都使用 print_r() 给出以下错误代码:
TypeError: 'undefined' is not a valid argument for 'in' (evaluating
'"default"in t')
http://localhost/js/uikit.min.js:3
http://localhost/js/uikit.min.js:3
http://localhost/js/uikit.min.js:3
(所以在这两种情况下脚本都已启动)
我的 PHP 脚本:
<?php
$token = $_GET['token'];
$simul_mail = $_GET['simulmail'];
$cmd = ' /var/www/html/hor/js/phantomjs';
$cmd.= ' /var/www/html/hor/js/_generate.js';
$cmd.= ' '.$token;
if(isset($_GET['simulmail'])&&isset($_GET['token'])){
exec($cmd, $output);
}
print_r( $output );
?>
我的 _generate.js 文件由 phantomJS 执行:
fs = require('fs');
system = require('system');
token = system.args[1];
if(token!=null && token!=""){
fs.changeWorkingDirectory('/var/www/html/hor/pdf/');
var page = new WebPage();
var pagename = "PDF_"+token+".pdf";
page.open('http://localhost/_template-mail.php?v='+token, function (status) {
page.render(pagename);
phantom.exit();
});
}
else{
phantom.exit();
}
我能做什么?
遇到同样问题的,是关于权限的问题
Apache 没有写入我的 PDF 文件夹的权限。
带有 exec() 的 PhantomJS 使用 PHP 的权限,它正在使用 Apache 的权限。
如果 Apache 是该文件夹的所有者,则效果很好!
--> sudo chown <your username>:<your usergroup> -R <path to>/folder
sudo chown apache -R /var/www/html/hor/pdf