首頁  >  文章  >  後端開發  >  fopen建文件建不了?

fopen建文件建不了?

WBOY
WBOY原創
2016-06-06 20:23:001098瀏覽

<code>


<form name="form 1" method="post" action="">
<table>
<tr>
<td>留言板</td>
<td><textarea name="LY" rows="8" cols="20"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="b1" value="显示"></td>
<td><input type="submit" name="b2" value="提交"></td>
</tr>
</table>
</form>


<?php $str=@$_POST["LY"];
$handle=fopen("E:\PHP2\phpnow\htdocs\1.txt","w+");
file_put_contents("E:\PHP2\phpnow\htdocs\1.txt",$str);
$filename="E:\PHP2\phpnow\htdocs\1.txt";
$num=readfile($filename);
fclose($handle);
?></code>

回复内容:

<code>


<form name="form 1" method="post" action="">
<table>
<tr>
<td>留言板</td>
<td><textarea name="LY" rows="8" cols="20"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="b1" value="显示"></td>
<td><input type="submit" name="b2" value="提交"></td>
</tr>
</table>
</form>


<?php $str=@$_POST["LY"];
$handle=fopen("E:\PHP2\phpnow\htdocs\1.txt","w+");
file_put_contents("E:\PHP2\phpnow\htdocs\1.txt",$str);
$filename="E:\PHP2\phpnow\htdocs\1.txt";
$num=readfile($filename);
fclose($handle);
?></code>

我觉得应该是锁的问题。在用fileput的时候,不需要打开文件了。

file_put_contents不需要fopen
fopen之后没有close,读写都会失败。

楼主的写法也实在太奇葩了,一般不可能会有这样的用法。

但纯就代码而言,我觉得1楼说的对,应该是个锁的问题,在FOPEN时,PHP程序就把文件锁定了,当然不可以再用file_put_contents写入文件内容了。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn