php fopen() failed to open file
Ader.Wu
Ader.Wu 2017-08-17 09:13:51
0
1
1508

$fild='./text.txt';

$userdata = fopen($fild,'ab');

if ($userdata==false){

echo 'Failed to open file';

}else{

echo 'Failed to open file';

$rel = fwrite($userdata,"aaaaa" );

fclose($userdata);

}

There is no problem with the code. In phpstorm’s own running environment http://localhost:63342, the file can be opened normally and write. But in http://localhost/, the file cannot be opened and written, and "Failed to open file" is displayed.

How to solve it?


Ader.Wu
Ader.Wu

reply all(1)
Ty80

You can use file_get_contents and file_put_contents to read and write files, which is easier. It is also possible that the file does not have read permission. Try changing the second parameter of fopen to w+.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!