LAMP installed on my local pc, as I know the string xxxx
can be written into /tmp/test
with below PHP function.
file_put_contents("/tmp/test","test1 test2")
cat ajax_get.php
<?php
$str = "test1 test2";
ini_set('display_errors', 1);
error_reporting(E_ALL);
$str = implode(" ",$_GET);
file_put_contents("/tmp/test",$str);
print($str);
?>
Why the command file_put_contents("/tmp/test",$str);
in ajax_get.php
can't work?
It is no use to replace file_put_contents
with
$handle=fopen("/tmp/test","w");
fwrite($handle,$str);
fclose($handle);
Maybe it is an issue on directory permission, if I change below statement in ajax_get.php
file_put_contents("/tmp/test",$str);
Into
file_put_contents("test",$str);
And run the previous process, ajax_get.php
create a file in /var/www/html/test
cat /var/www/html/test
test1 test2
Show the permission for /tmp
directory.
ls -al /tmp
total 76
drwxrwxrwt 16 root root 12288 Dec 10 18:39 .
drwxr-xr-x 23 root root 4096 Dec 1 08:03 ..
.
is the current directory /tmp
, its permission is 777 (rwxrwxrwx),
why can't write file into /tmp
directory by PHP?
/tmp
. – Shifflettfile_put_contents("/tmp/test",$str);
? E.g.$ret = file_put_contents("/tmp/test",$str);
. This would tell you if you are actually writing any bytes or not. – Astronomical