An example of how to call a shell script with php

This site has some interesting code to modify images and I ran the code by:

  1. Download the script and upload it to your server.
  2. Change the permissions to 755 on the script
  3. Write your php code like this using the full path to the script
    <?php
    // Run the script
    exec("/FULL PATH TO AUTOTRIM/autotrim.sh zelda3_border2w.png fred.png 2>&1"$array); 
    //Display any errors
    echo "<br>".print_r($array)."<br>"
    echo 
    "</pre>";
    ?>

An alternative method

<?php
$cmd
=" bash /FULL PATH TO AUTOTRIM/autotrim.sh zelda3_border2w.png fred.png";
exec($cmd,$result);

if(
$result=="0")
echo 
"sucess";
else
echo
"fail";
?>

When I ran the code I recived an error:
/autotrim.sh: line 271: bc: command not found
bc is a calculator that is built into Unix/Linux.

I ran this code to get some information about the path for bc and it did not return anything so I assumed bc was not installed.
I contacted my hosts who installed it and the code worked OK.

<?php
echo "<pre>";
system('which bc',$path); print_r($path); 
echo 
"</pre>";
?>

I was also told that I may have been able to install the bc binarys ( although I could not find them ) and use the path to those in the code. I did not need to try that so I do not know if it would have worked or not.