views:

30

answers:

2

Hi 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

A: 

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?

symcbean
A: 

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
Max