0

I'm trying to check before running a php script if pdftohtml is installed on server.

Is there a way to check if pdftohtml is installed on server (linux or mac) from within the code.

I'm looking for something similar to function_exists()

Szekelygobe
  • 2,309
  • 1
  • 19
  • 25

1 Answers1

1

Perhaps, the following will solve your case:

$isInstalled = (bool) shell_exec('which pdftohtml');

which returns nothing if the program isn't found. But it will only work if it's installed globally (without specifying an absolute path). And returns a full path if it's there

Fogus
  • 366
  • 1
  • 2
  • 13
  • for some reason `shell_exec` it doesn't return a value. I also tried `shell_exec('pdftohtml -v')`. If I run the command in the terminal then it returns a value. – Szekelygobe Dec 08 '20 at 11:32
  • It seems `pdftohtml` doesn't exist on the server. Check something else: `shell_exec('which which')` – Fogus Dec 08 '20 at 11:34
  • If I run the command in terminal `which pdftohtml` then it returns the path `/usr/local/bin/pdftohtml` – Szekelygobe Dec 08 '20 at 11:35
  • 2
    It may be related to a current user if you run php from another user. Run `whoami` from PHP and in the terminal. But if you run both as the same user, there should be something else. For example, `shell_exec` can be disabled. You may also run another function like `exec('which pdftohtml', $output, $result);` (there is a big chance it will be also disabled) – Fogus Dec 08 '20 at 11:40
  • Actually, if `shell_exec` is disabled, probably, you won't be able to run `pdftohtml` as well. Check `function_exists('shell_exec')`. Of course, you should see if it didn't exist when you ran `shell_exec` before, but maybe your script doesn't show errors and it was the end of your script. – Fogus Dec 08 '20 at 11:45
  • If I run other commands like `which which` it returns the path, doesn't return it for `pdftohtml`. If I run the script to transform pdf files to html it works, so there is a working `pdftohtml` installed on the server. interesting.... – Szekelygobe Dec 08 '20 at 11:45
  • You may also check (debug) how your script runs `pdftohtml` to transform what you need. There you should find the correct way of running it. And then use the same to check. E.g. replace all the params of `pdftohtml` to `-v`. Or something similar – Fogus Dec 08 '20 at 11:47