note 119828 added to function.fopen
| From: | arnold at nijboer dot it | Date: | Fri, 02 Sep 2016 07:42:34 +0000 |
| Subject: | note 119828 added to function.fopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206459@lists.php.net to get a copy of this message | ||
if not provided with a handle, fopen will close automatic!
so instead of
<?php
function mk_file($filename) {
if(!is_file($filename)) {
fclose(fopen($filename,"x")); //create the file and close it
return true;
} else return false; //file already exists
}
?>
as gmdebby suggested.
you can do
<?php
if(fopen($filename,"x+")) {
file_put_content($filename,$str);
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 94.213.249.150
----
Manual Page -- http://php.net/manual/en/function.fopen.php
Edit -- https://master.php.net/note/edit/119828
Del: integrated -- https://master.php.net/note/delete/119828/integrated
Del: useless -- https://master.php.net/note/delete/119828/useless
Del: bad code -- https://master.php.net/note/delete/119828/bad+code
Del: spam -- https://master.php.net/note/delete/119828/spam
Del: non-english -- https://master.php.net/note/delete/119828/non-english
Del: in docs -- https://master.php.net/note/delete/119828/in+docs
Del: other reasons-- https://master.php.net/note/delete/119828
Reject -- https://master.php.net/note/reject/119828
Search -- https://master.php.net/manage/user-notes.php