<?php
echo "<pre>";
system("type convert");
echo "</pre>";
?>
convert is /usr/local/bin/convert
<?php
echo "<pre>";
system('which convert',$path); print_r($path);
echo "</pre>";
?>
/usr/local/bin/convert 0
'which' is a program that is generally on ALL UNIX machines, which searches the users command 'PATH' to find the given program.
'type' is a shell built in that does the same thing but just looking up the result from the saved results of the shells own search when it started up, it also returns builtins, alias and functions of that name that may be defined in the shell.
'locate' is a simular command that is available on more modern UNIX machines (typically Linux and MacOX) which just finds files (not commands) containing that name. It can also be useful for the above, but it will not always work on all OSs. It will find the 'convert' when it is NOT on the system supplied PATH to the PHP script.
To make the code more portable you can use this to get the path to convert from the server and automaticaly put it into your code.
<?php
// In my case $HTTP_ENV_VARS['PATH'] = bin:usr/bin
$env_vars = explode( ':', $HTTP_ENV_VARS['PATH']);
// Combine the required part from $HTTP_ENV_VARS['PATH'] and convert for your path.
$env_path = $env_vars[1]."/convert";
// Now $env_path = usr/bin/convert
// Use like:
exec("$env_path image.jpg -resize 100x100 output.jpg");
?>
This page uses the Perfect 'Left Menu' 2 Column Liquid Layout by Matthew James Taylor. View more website layouts and web design articles.