php 中 exec() 引用的图像的正确路径

发布于 2024-09-17 17:20:04 字数 365 浏览 13 评论 0原文

我正在尝试使用以下脚本来计算 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酷到爆炸 2024-09-24 17:20:04

您是否检查过 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?

复古式 2024-09-24 17:20:04

首先,您应该确保 pdf 文件的路径存在,如下所示:

$filename = "...";

// Brute force, maybe you could use some other "nicer" error handling
if(!file_exists($filename)) die('File does not exist!');

然后,我会检查

  • PHP 是否具有执行 Imagemagick 命令的访问权限(对 Imagemagick dir/executables 的访问权限)
  • 允许 Imagemagick 读取该文件并写入指定的路径(目录/文件访问权限),
  • 您的 Imagemagick 安装实际上可以识别 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:

$filename = "...";

// Brute force, maybe you could use some other "nicer" error handling
if(!file_exists($filename)) die('File does not exist!');

Then, I would check if

  • PHP has the access rights to execute Imagemagick commands (access rights to the Imagemagick dir/executables)
  • Imagemagick is allowed to read the file and write to the specified path (directory/file access rights)
  • your Imagemagick installation can actually identify PDF files (I tried it on my local machine (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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文