开发者

PHP system returns 4

开发者 https://www.devze.com 2022-12-23 09:21 出处:网络
I want to convert a pdf file to an image with PHP, but i can\'t get the command worked. PHP returns a 4. I don\'t have any kind of 开发者_开发技巧idea what that can be.

I want to convert a pdf file to an image with PHP, but i can't get the command worked. PHP returns a 4. I don't have any kind of 开发者_开发技巧idea what that can be.

I am using the next code:

$tmp = system("convert -version", $value); 
var_dump($value);

Someone an idea?


try

  exec("convert -version 2>&1", $out, $ret);
  print_r($out);

it should tell you what's wrong


It looks like the -version flag is telling the convert software (looks like imagemagick) to respond with the major version number of that software. It looks like it is working correctly. You probably need to pass it the right flags to operate properly. I suggest reading the documentation to see what flags are required to convert PDFs.


try using some of the other system functions in PHP to get more detailed output.

exec("convert -version", $output, $value);
print_r($output);

The exec function above will give you all the output from the command in the $output parameter, as an array.

The return status (which will be held in the $value parameter in the exec call above or the system call in your original code) gives you the return value of the executed shell command.

In general, this will be zero for success, with non-zero integer return values indicating different kinds of error. So it appears there's something wrong with the command as you have it (possibly -version is not recognised: often you need a double hyphen before long-hand command-line options).

Incidentally, you may also find that the passthru function is more suited to your needs. If your convert program generates binary image data corresponding to the converted PDF, you can use passthru to send that image data directly to the browser (after setting the appropriate headers of course)


err... aren't you vardumping the wrong result? (I would var dump $tmp, not $value.)

I think the code should read:

$tmp = system("convert -version", $value); 
var_dump($tmp);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号