elite_prodigy Posted April 14, 2008 Share Posted April 14, 2008 I'm using the following to open a file: <?php $local = "overall.css"; $css_file = fopen($local, "w+"); $CSS = fread($css_file, 400000); fclose($css_file); ?> The following is supposed to display the output: <textarea name="css" rows="35" cols="75" wrap="virtual"><?php echo $CSS; ?></textarea> But, everytime I view the page that opens and reads the file, the file is empty! I don't think I'm doing anything wrong, but obviously something isn't working right. Can someone please help me? Quote Link to comment https://forums.phpfreaks.com/topic/101098-solved-file-is-wiped-blank-when-opened-with-fopen/ Share on other sites More sharing options...
micah1701 Posted April 14, 2008 Share Posted April 14, 2008 are you running the scrip in the same directory as the file "overall.css" is stored? It could be that the script is not really find the file you think you're looking for and is showing a new, blank page. perhaps you could try the full path to the file. $local = "/var/www/mywebsite/path/to/overall.css"; Quote Link to comment https://forums.phpfreaks.com/topic/101098-solved-file-is-wiped-blank-when-opened-with-fopen/#findComment-517035 Share on other sites More sharing options...
elite_prodigy Posted April 14, 2008 Author Share Posted April 14, 2008 That didn't work. It's the right file, I just recreates the file when opened. Maybe changing the mode will help? Quote Link to comment https://forums.phpfreaks.com/topic/101098-solved-file-is-wiped-blank-when-opened-with-fopen/#findComment-517039 Share on other sites More sharing options...
elite_prodigy Posted April 14, 2008 Author Share Posted April 14, 2008 Fixed! For now! <?php $local = "overall.css"; $css_file = fopen($local, "r"); //changed mode to "r" $CSS = fread($css_file, 400000); fclose($css_file); ?> Quote Link to comment https://forums.phpfreaks.com/topic/101098-solved-file-is-wiped-blank-when-opened-with-fopen/#findComment-517044 Share on other sites More sharing options...
rhodesa Posted April 14, 2008 Share Posted April 14, 2008 Yes, a mode of 'w' is for writing to a file (which will empty it). If you are just looking to read, stick with the 'r' mode. Another way of doing it is with: <?php $CSS = file_get_contents("overall.css"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/101098-solved-file-is-wiped-blank-when-opened-with-fopen/#findComment-517045 Share on other sites More sharing options...
elite_prodigy Posted April 14, 2008 Author Share Posted April 14, 2008 Thanks to everyone who answered! I so can't wait to finish the registration system! Quote Link to comment https://forums.phpfreaks.com/topic/101098-solved-file-is-wiped-blank-when-opened-with-fopen/#findComment-517075 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.