As mentioned, my current website directory is /var/www/html (777 permissions)
Then my
/var/www/html/g/data/visit.php file
<code>require("../function.php"); if (file_exists($_SERVER["DOCUMENT_ROOT"]. "/cache/vc-$date.json")) { echo file_get_contents($_SERVER["DOCUMENT_ROOT"]. "/cache/vc-$date.json"); } else { $res=get_sum(); $days1=get_days(1); $month=get_this_month(); $result=["visit"=>$res,'days'=>$days1,'month'=>$month]; $echo = json_encode($result); cache_this($echo,'vc-'.$date); echo $echo; } </code>
function.php
<code>function cache_this($result,$name){//内容,命名规则 //file_put_contents("/cache/$name.json", $result)or die("Unable to open file!"); $myfile = fopen($_SERVER['DOCUMENT_ROOT']."/cache/$name.json", "w") or die("Unable to open file!"); $txt = $result; fwrite($myfile, $txt); fclose($myfile); }</code>
This is part of the result of my ls -l
<code>-rwxrwxrwx. 1 root root 81 11月 4 2013 bottom.php drwxrwxrwx. 2 apache apache 4096 11月 10 17:09 cache</code>
Then I looked at the user and group in httpd.conf, and they were all correct for apache.
But the json file just couldn’t be written into the cache folder, and $myfile always returned false.
Please tell me what the problem is. I have been struggling all night. The Double Eleven centos discussion group is full of troubles and I can’t find out what is going on...
Urgent request……………… (powerless
As mentioned, my current website directory is /var/www/html (777 permissions)
Then my
/var/www/html/g/data/visit.php file
<code>require("../function.php"); if (file_exists($_SERVER["DOCUMENT_ROOT"]. "/cache/vc-$date.json")) { echo file_get_contents($_SERVER["DOCUMENT_ROOT"]. "/cache/vc-$date.json"); } else { $res=get_sum(); $days1=get_days(1); $month=get_this_month(); $result=["visit"=>$res,'days'=>$days1,'month'=>$month]; $echo = json_encode($result); cache_this($echo,'vc-'.$date); echo $echo; } </code>
function.php
<code>function cache_this($result,$name){//内容,命名规则 //file_put_contents("/cache/$name.json", $result)or die("Unable to open file!"); $myfile = fopen($_SERVER['DOCUMENT_ROOT']."/cache/$name.json", "w") or die("Unable to open file!"); $txt = $result; fwrite($myfile, $txt); fclose($myfile); }</code>
This is part of the result of my ls -l
<code>-rwxrwxrwx. 1 root root 81 11月 4 2013 bottom.php drwxrwxrwx. 2 apache apache 4096 11月 10 17:09 cache</code>
Then I looked at the user and group in httpd.conf, and they were all correct for apache.
But the json file just couldn’t be written into the cache folder, and $myfile always returned false.
Please tell me what the problem is. I have been struggling all night. The Double Eleven centos discussion group is full of troubles and I can’t find out what is going on...
Urgent request……………… (powerless
View SELinux status
Why do you have to write to the root directory? Can’t the current directory work?