fopen建文件建不了?

WBOY
Release: 2016-06-06 20:23:00
Original
1129 people have browsed it

<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>
Copy after login
Copy after login

回复内容:

<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>
Copy after login
Copy after login

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

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

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

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

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template