According to fopen documentation, in some modes it will create the file if it does not exist, but in my situation, I've checked all 'w', 'w+', 'x' and 'x+' modes but it's just throwing warnings at me and it cannot create the file.
It's my code:
$this->handle = fopen($this->log_name, 'w');
and what I get:
Warning: fopen(D:\xampp\htdocs\farid\logs\error.php) [function.fopen]: failed to open stream: No such file or directory in D:\xampp\htdocs\farid\libraries\error\log.php on line 34
Warning: fwrite() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\farid\libraries\error\log.php on line 66
Warning: fclose() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\farid\libraries\error\log.php on line 27
And I'm working in windows environment.
The fopen() function is also used to create a file. Maybe a little confusing, but in PHP, a file is created using the same function used to open files. If you use fopen() on a file that does not exist, it will create it, given that the file is opened for writing (w) or appending (a).
The fopen function creates the file if it does not exist.
The fopen() function opens a file or URL. Note: When writing to a text file, be sure to use the correct line-ending character! Unix systems use \n, Windows systems use \r\n, and Macintosh systems use \r as the line ending character.
Check if the path to the logfile exists, it creates a file, not a directory.
Also check if the user, which runs xampp, has access to the folder you specified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With