I am trying to convert PDF to JPG file with this code:
$pdf_file = 'text.pdf';
$save_to = 'demo.jpg'; //make sure that apache has permissions to write in this folder! (common problem)
//execute ImageMagick command 'convert' and convert PDF to JPG with applied settings
exec('convert '.$pdf_file.' '.$save_to, $output, $return_var);
if($return_var == 0) { //if exec successfuly converted pdf to jpg
print "Conversion OK";
}
else print "Conversion failed.<br />".$output;
And I get message Conversion OK but image file don’t creates. When I tried this on the different server, then everything works.
Permissions for root catalog are set to 777. I don’t have any idea why it doesn’t work… I don’t know which versions of Imagemagick are installed on both servers. Maybe that is the problem ? In phpinfo() there is no information about version or anything.
You are having trouble running “convert” because the PHP function exec() has been disabled in your php.ini file.
When a exec() command is failing there are multiple steps that can be taken to troubleshoot the problem:
Verify if safe mode is on. Specifically the docs say:
Turn on Error Reporting too see if that gives any more information. This can be accomplished by adding code like the following to the top of your script:
Simplify the exec() command to something that should always work:
In your specific case when you tried step #3 above, it returned null. Null is what PHP returns when the exec() function is disabled. Also, if you were able to turn on error reporting (step #2) the output would have looked something like the following:
The solution to this problem is to enable the exec function in php.ini or go to a host/server that allows the function to be used.