Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Exec Not running, but command works ok!

Tags:

php

I have the following script to take an uploaded PDF in PHP and call ImageMagik/Ghostscript to convert to images of specified size.

$tmp = exec("convert \"{$strPDF}\" -resize 500X500 \"{$strOut}\"", $results); 

However, this doesnt seem to work. No errors in the log file and no errors on screen. If I do the following,

$tmp = exec("convert \"{$strPDF}\" -resize 500X500 \"{$strOut}\"", $results); 
echo ("convert \"{$strPDF}\" -resize 500X500 \"{$strOut}\"");

And I paste the output into a command prompt it works fine (It takes around 6-10 seconds - My max_execution_time is at 600.

Any suggestions on why this might not be working?

This is Windows, IIS 7 and PHP5.

Edit: I'm having the same issue in both CentOS and Windows. Both have ImageMagik and Ghostscript installed.

Edit Edit the below still fails.

$handle = popen("convert \"{$strPDF}\" -resize 500X500 \"{$strOut}\"","r");
        echo "'$handle'; " . gettype($handle) . "\n";
        $read = fread($handle, 2096);
        echo $read;
        pclose($handle);
like image 362
LiamB Avatar asked Mar 03 '26 13:03

LiamB


2 Answers

Try adding 2>&1 to the end of your command. I found it here.

exec('some_command 2>&1', $output);
print_r($output);  // to see the respond to your command
like image 156
user Avatar answered Mar 06 '26 03:03

user


in php.ini maybe this function exec declare under

disable_functions

or if you run in

safe mode

This function is disabled when PHP is running in safe mode.

like image 32
Haim Evgi Avatar answered Mar 06 '26 02:03

Haim Evgi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!