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"

_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to