[nycphp-talk] Checking if a program is installed
Rob Marscher
rmarscher at beaffinitive.com
Thu Dec 27 10:33:21 EST 2007
On Dec 19, 2007, at 12:51 PM, Web Scribble - Alexey Gutin wrote:
> I am trying to check if a program is installed on the server through
> PHP. In particular, FFMPEG. In Linux, I can just run “ffmpeg”, and
> the shell will throw an error if it isn’t found. The same happens in
> Windows.
Sorry for replying to a relatively old thread. I've been on
vacation. But I see know one exactly answered this - the
is_executable only works if you know the exact absolute path that the
program would be installed at. The following should work on a unix
based machine. There's got to be something similar for Windows, but I
don't want to reboot my Mac to try to figure it out :)
<?php
function getCommandPath($command = '')
{
// note: security vulnerability...
// should validate that $command doesn't
// contain anything bad
$path = `which $command`;
if ($path != null) {
$path = trim($path); // get rid of trailing line break
return $path;
} else {
return false;
}
}
var_dump(getCommandPath('ffmpeg'));
var_dump(getCommandPath('php'));
On my machine (which doesn't have ffmpeg), I get this output:
bool(false)
string(18) "/usr/local/bin/php"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20071227/d84874ca/attachment.html>
More information about the talk
mailing list