MK27 Posted June 17, 2010 Share Posted June 17, 2010 I'm trying to write debugging data to a file. I open the file: $dfile = fopen("debug/PHPdebug.txt","w") || die; The process continues, so $dfile is a valid handle (???) Next I write to the file: fwrite($dfile, "this data will not appear\n"); However, that data does not appear, and in the apache error log I get "PHP Warning: fwrite(): supplied argument is not a valid stream resource". The directory "debug" is owned by apache and set 755 (I've tried 777 too). The file does get created each time. Just to be clear: the fopen works, but the fwrite on the handle returned does not. Why can I open a file and then not use the handle? Googling for this issue is proving useless, since it's all people who's fopen() also failed because of permissions or whatever. Quote Link to comment https://forums.phpfreaks.com/topic/205113-fopenw-creates-file-then-fwrite-on-handle-cause-invalid-stream/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 17, 2010 Share Posted June 17, 2010 Use OR instead of || Because || has a lower precedence than =, your code is or'ing the result of fopen() with die; (which is nothing) and assigning that to $dfile. If you had error_reporting set to E_ALL, you would also see the following Warning that would help you track down what your code is doing - Warning: fwrite() expects parameter 1 to be resource, boolean given in your_file.php on line x Quote Link to comment https://forums.phpfreaks.com/topic/205113-fopenw-creates-file-then-fwrite-on-handle-cause-invalid-stream/#findComment-1073667 Share on other sites More sharing options...
MK27 Posted June 17, 2010 Author Share Posted June 17, 2010 OR instead of || (is lower than =) eh? LOL... That would explain why the value of $dfile was 1 when the file opened but zilch when the permissions were wrong. Heh-heh. Thanks much PFMaBiSmAd. I've set error_reporting to E_ALL, too, the more the merrier. Quote Link to comment https://forums.phpfreaks.com/topic/205113-fopenw-creates-file-then-fwrite-on-handle-cause-invalid-stream/#findComment-1073669 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.