警告fopen(),fwrite(),fclose()

时间:2015-09-09 04:53:01

标签: php fopen fwrite fclose

我在调用php文件时有一些错误 错误是

Warning: fopen(beasweb/1qHdAfvx1GQPUzef4BGiEg$21J.in): failed to open stream: No such file or directory in C:\xampp\htdocs\beasweb\index.php on line 140

Warning: fwrite() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\beasweb\index.php on line 142

Warning: fclose() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\beasweb\index.php on line 143

并且线140,142,143是

$fh = fopen($filename, 'a');                                ///140
$filestring=chr(239).chr(187).chr(191).$filestring;
fwrite($fh, $filestring);                                   ///142
fclose($fh);                                                ///143

我的代码中出现了什么问题? 有谁能解决我的问题? 感谢

1 个答案:

答案 0 :(得分:1)

您使用webBrowser1.Url = new Uri("http://mdp.ihio.gov.ir/mdp/SAP");模式时出现错误,如果文件不存在,则必须创建文件。或使用a模式创建以防万一文件不存在。

所以请使用a+

  

a:仅限写作;将文件指针放在文件的末尾。如果该文件不存在,请尝试创建它。在此模式下,fseek()仅影响读取位置,始终附加写入。

从php手册中引用

  

fopen($filename, 'a+'); 开放阅读和写作;将文件指针放在文件的末尾。如果该文件不存在,请尝试创建它。在此模式下,fseek()仅影响读取位置,始终附加写入。