fopen() will open the resource in the same directory as the file executing the command. In other words, if you just run the ~ / test.php file, your script will create the ~ / myText.txt file.
This can be a bit confusing if you use URL rewriting (for example, in MVC), as this will most likely create a new file in any directory that contains the root.php file.
In addition, you must have the correct permissions set and you can test them before writing to a file. The following will help you debug:
$fp = fopen("myText.txt","wb"); if( $fp == false ){ //do debugging or logging here }else{ fwrite($fp,$content); fclose($fp); }
Farray Feb 13 '12 at 17:53 2012-02-13 17:53
source share