PHP Execute with > - Close

104 Views Asked by At

i try to make this:

<?php
error_reporting(E_ALL);
echo "<HTML><BODY>";
exec("echo Hallo > /tmp/testtt.txt", $output, $retval);
echo "Rückgabe mit Status $retval und Ausgabe:\n<br/>";
foreach($output as &$s){
       echo $s."<br/>";
}
echo "</BODY></HTML>";
?>

i already tried system, passthru, exec, popen but, it never creates /tmp/testtt.txt Rights of /tmp:

drwxrwxrwt  10 root root 220K Mai  3 10:28 tmp

What is my mistake?

2

There are 2 best solutions below

3
On

Try this

exec('sh -c "echo Hallo > /tmp/testtt.txt"', $output, $retval);
1
On

The Problem was the Sticky bit. /tmp/ has a Sticky bit - so there is a Problem with the PHP exec...