Page 1 of 1

exec Path

Posted: 2012-07-06T06:21:10-07:00
by mssbcons
My admin installed Ghostscript and ImageMagik which I am told is at /usr/bin (eg /usr/bin/convert). As I am converting pdf to png, jpegs ect what would my full exec line be?

I found this but surely the path has to be included
<?php
//the path to the PDF file
$strPDF = "my_pdf.pdf";
exec("convert \"{$strPDF}\" -colorspace RGB -geometry 1024 \"output.png\"");
?>

So would it read

exec("/usr/bin/convert \"{$strPDF}\" -colorspace RGB -geometry 1024 \"output.png\"");

Re: exec Path

Posted: 2012-07-06T07:55:37-07:00
by Bonzo
I did not use the path on my old install and just used convert but since my hosts upgraded I now have to use /usr/local/bin/convert It depends on your setup. Have you tried anything?

This should work as long as you do not have spaces in your filenames - you do not need the { } and extra \"

Code: Select all

exec("convert $strPDF -colorspace RGB -geometry 1024 output.png");

Re: exec Path

Posted: 2012-07-07T08:50:08-07:00
by mssbcons
Thanks for the path advice I have used both:

But

$strPDF = $_SERVER['DOCUMENT_ROOT']."pdfTest.pdf";
exec("/usr/local/bin/convert $strPDF -colorspace RGB -geometry 1024 output.png");
print "finished";

gives

finished

But output.png is not generated

How know what exec is returning as an error? Thanks again much appreciated

Re: exec Path

Posted: 2012-07-07T09:12:19-07:00
by Bonzo
If you want confirmation all is OK I would add some code after the exec() to see if the file exists - some times that gives a false result so I tend to try opening the file. This means the file has definatly been creted.

As to error reporting:

Code: Select all

$strPDF = $_SERVER['DOCUMENT_ROOT']."pdfTest.pdf";
$array=array(); 
echo "<pre>";
exec("/usr/local/bin/convert $strPDF -colorspace RGB -geometry 1024 output.png 2>&1", $array);  
echo "<br>".print_r($array)."<br>";  
echo "</pre>";

Re: exec Path

Posted: 2012-07-08T03:18:42-07:00
by mssbcons
Thanks again for helping

Regardless of path this returns an empty array and a screen output of 1.

$strPDF = $_SERVER['DOCUMENT_ROOT']."/imageTest.php";
$array=array();
echo "<pre>";
exec("/usr/local/bin/convert $strPDF -colorspace RGB -geometry 1024 output.png 2>&1", $array);
echo "<br>".print_r($array)."<br>";
echo "</pre>";

i.e.

Array
(
)
1

Re: exec Path

Posted: 2012-07-10T02:53:33-07:00
by mssbcons
I have discovered 'safe mode' on php needs to be set to off for exec to work. I now get a permissions error which I will follow up on. Thanks again for your help.