php 中 exec() 引用的图像的正确路径
我正在尝试使用以下脚本来计算 pdf 文件中的 pdf 页数。
$filename = $_ENV{'HOMEDIR'}."/www/path/to/pdf/file";
$cmd = "/usr/local/nf/bin/identify -density 12 -format '%p' '$filename' ";
$out = array();
exec($cmd,$out,$error);
foreach($out as $f=>$v)
{
echo "$f = $v ";
}
但是我没有得到任何输出。我认为这是一个与路径相关的问题。如何在命令行命令中引用路径?请任何帮助指导!
谢谢 拉胡尔
I am trying to use the following script to count the number of pdf pages in a pdf file.
$filename = $_ENV{'HOMEDIR'}."/www/path/to/pdf/file";
$cmd = "/usr/local/nf/bin/identify -density 12 -format '%p' '$filename' ";
$out = array();
exec($cmd,$out,$error);
foreach($out as $f=>$v)
{
echo "$f = $v ";
}
However I get no output. I think its a path related issue. How to refer to paths in command line commands? Any help guidance please !
thanks
Rahul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否检查过 PHP 是否报告了任何错误? PHP 代码中是否出现任何错误?您是否尝试过检测代码以检测潜在问题(例如 print var_export(file_exists($filename), true);?您检查过 exec(...) 的返回值吗?由 exec( 设置的变量 $error 的内容...)?您是否验证了可执行文件(identify)的路径是否正确?对于网络服务器来说,它可能与通过 ssh / telnet / console 访问系统时不同。您是否检查过“identify”是否可执行。网络服务器 uid 是否检查过 pdf 文件是否可以被网络服务器 uid 读取?
Have you checked to see if any errors are being reported by PHP? If any errors are occurring in the PHP code? Have you tried instrumenting your code to detect potential issues (e.g. print var_export(file_exists($filename), true);? Have you checked the return value of exec(...)? The contents of the variable $error set by exec(...)? Have you verified that the path to the executable (identify) is correct? It may be different for the webserver than when you access the system via ssh / telnet / console. Have you checked if 'identify' is executable by the webserver uid? Have you checked if the pdf file is readable by the webserver uid?
首先,您应该确保 pdf 文件的路径存在,如下所示:
然后,我会检查
ImageMagick 6.1.7
)上尝试过,但 IM 失败,并显示此错误:identify: Postscript delegate failed ...
) - 可能 Imagemagick 需要 Ghostscript 才能处理 PDF 文件First, you should make sure the path to the pdf file exists, something like this:
Then, I would check if
ImageMagick 6.1.7
) using the command line and IM failed with this error:identify: Postscript delegate failed ...
) - probably Imagemagick needs Ghostscript to work with PDF files