Arn*_*hor 0 php apache file-io
好吧,我开始讨厌PHP了.我有一个文件,它是完全可读的(is_readable返回true),具有777权限,通常由fopen打开,但file_get_contents返回false.代码如下:
<?php
error_reporting(-1);
$handle = fopen("tres.txt","w+");
try{
$cnt = file_get_contents("/var/www/tres.txt");
}
catch(Exception $err){ echo $err->getMessage(); }
if ($handle) echo "Allright!", "<br />";
if ($cnt) echo "Good";
if(is_readable("/var/www/tres.txt")) echo " Is";
?>
Run Code Online (Sandbox Code Playgroud)
即使我打开了我知道的所有错误报告选项,也没有发现任何错误,这让我很生气.将文件路径更改为"tres.txt"的"./tres.txt"也没有任何效果.问题可能在哪里?
PS它运行在PHP5和apache2上.
fopen("tres.txt","w+");截断文件.在那之后阅读它是没有意义的.
$cnt很可能不是假的,而是在布尔上下文中''考虑的空字符串false.
if ($cnt !== false) echo "Good"; 可能输出"好".
| 归档时间: |
|
| 查看次数: |
3059 次 |
| 最近记录: |