Running linux shell script with PHP-ThrowExceptions

Exception or error:

I have created shell script:

if [ -f "$file" ]
    echo "Found."
    echo "Not found."
IfcConvert --use-element-guids /home/upload/ftp/${1}.ifc /home/upload/ftp/${1}.dae

When I go to linux terminal and execute it from there with

./ drevodomek

everything works fine.. I got “Found.” message and also converter executes

But when I created helper.php

if (file_exists("/home/upload/ftp/drevodomek.ifc"))  
    echo "The file exists"; 
    echo "The file does not exists"; 

$cmd = "./ drevodomek";
$results = shell_exec($cmd);
echo $results

I get answers:

“The file exists.” from PHP,

“Found.” from

IfcConvert: input file “/home/upload/ftp/drevodomek.ifc” doesn’t exists. from

I am new to linux, has anyone any idea what is the difference running script from terminal and with shell_exec()? Thanks!

How to solve:

The problem was with the rights, seems like terminal was run as root, but php exetuted script as normal user. Always check your 777!

Leave a Reply

Your email address will not be published. Required fields are marked *