rockinaway Posted September 9, 2007 Share Posted September 9, 2007 if ($fp = @fopen('folder/file.php', "w")) { // Write the data to the file fwrite($fp, $data); // Close the file fclose($fp); } else echo $_POST['content']; My script won't open the file and write the content.. the $data is declared.. is there something I am missing? Link to comment https://forums.phpfreaks.com/topic/68582-fopen-not-working/ Share on other sites More sharing options...
GingerRobot Posted September 9, 2007 Share Posted September 9, 2007 Well, it would be nice if you told us what does happen when you try this code. However, im going to assume that nothing happens - ie, you get no error messages, but there is no writing to the file. If you are having problems with a script, it's generally a good idea to remove the error suppresion(@). Try changing this line: if ($fp = @fopen('folder/file.php', "w")) To: if ($fp = fopen('folder/file.php', "w")) Post the error message if you get one. Link to comment https://forums.phpfreaks.com/topic/68582-fopen-not-working/#findComment-344761 Share on other sites More sharing options...
rockinaway Posted September 9, 2007 Author Share Posted September 9, 2007 Warning: fopen(folder/file.php) [function.fopen]: failed to open stream : Permission denied in test.php That is what I get (modified file names ) The folders have got the correct permissions though.. Link to comment https://forums.phpfreaks.com/topic/68582-fopen-not-working/#findComment-344795 Share on other sites More sharing options...
rockinaway Posted September 9, 2007 Author Share Posted September 9, 2007 The files have got permissions of 644, and the folders 777 Link to comment https://forums.phpfreaks.com/topic/68582-fopen-not-working/#findComment-344798 Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2007 Share Posted September 9, 2007 file permissions of 644 will probably not allow a write by the server. Also, you might want to use the complete path to the file. fopen("/home/somewhere/folder/file.php","w"); Link to comment https://forums.phpfreaks.com/topic/68582-fopen-not-working/#findComment-344800 Share on other sites More sharing options...
rockinaway Posted September 9, 2007 Author Share Posted September 9, 2007 Ok I changed the permissions.. but now when my file is written, hunderds of \s appear before my quotes and then there are extra linebreaks ater every line.. Link to comment https://forums.phpfreaks.com/topic/68582-fopen-not-working/#findComment-344801 Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2007 Share Posted September 9, 2007 don't know what that is, haven't seen $data. Link to comment https://forums.phpfreaks.com/topic/68582-fopen-not-working/#findComment-344803 Share on other sites More sharing options...
rockinaway Posted September 9, 2007 Author Share Posted September 9, 2007 I have added stripslashes() but that doesn't seem to have any effect Link to comment https://forums.phpfreaks.com/topic/68582-fopen-not-working/#findComment-344804 Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2007 Share Posted September 9, 2007 what is in $data? Can you show us? Link to comment https://forums.phpfreaks.com/topic/68582-fopen-not-working/#findComment-344805 Share on other sites More sharing options...
rockinaway Posted September 9, 2007 Author Share Posted September 9, 2007 Data it just the contents from a previous PHP file, that is sent through $_POSTS, via a textarea in a form. So it contains lots of the $,'," stuff... Link to comment https://forums.phpfreaks.com/topic/68582-fopen-not-working/#findComment-344807 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.