bahstudios Posted May 30, 2009 Share Posted May 30, 2009 <?php //Basic variables $currentpage = $_GET['page']; $today = date("l"); $hour = date("Gis"); $update = ($hour == "00000"); $File = "lastfriday.txt"; $fh = fopen($File, 'r'); $start = fread($fh, filesize($File)); fclose($fh); // Determine day of the week and the day's variable if($today == "Monday") { ($lastpage = $start + 1); } elseif($today == "Tuesday") { ($lastpage = $start + 2); } elseif($today == "Wednesday") { ($lastpage = $start + 3); } elseif($today == "Thursday") { ($lastpage = $start + 4); } // Looks like it's time to update! elseif($today == "Friday" && $hour == $update) { ($lastpage = $start + 5); $Handle = fopen($File, 'w'); $Data = "$lastpage"; fwrite($Handle, $Data); fclose($Handle); } elseif($today == "Friday") { $lastpage = $start; } //Whoops! It's the weekend! No change in the data for two days! elseif($today == "Sunday") { ($lastpage = $start); } elseif($today == "Saturday") { ($lastpage = $start); } ?> All lastfriday.txt contains is a number - currently 615. What I want the code to do is take the number from lastfriday.txt and add a certain number to it each day, so that $lastpage is a new number for each weekday. That part works fine up to Thursday. I run into trouble on Friday - what Friday's script is supposed to do is right at midnight, take $start + 5's total and use that number to overwrite the old data in lastfriday.txt, making it the NEW $start number so it can continue on next week. Every week should end with the number in lastfriday.txt being 5 more than it was the previous week. lastfriday.txt is CMODed to 777, and I've tested it with other, separate data file writing codes to where it works - so I must be doing something wrong with this code, possibly in the way the time fires off on Friday? Link to comment https://forums.phpfreaks.com/topic/160294-write-file-not-working/ Share on other sites More sharing options...
bahstudios Posted May 31, 2009 Author Share Posted May 31, 2009 I THINK I've gotten it fixed, but can someone confirm whether this will work or not? Here's the new code: <?php //Basic variables $currentpage = $_GET['page']; $today = date("l"); $hour = date("Gis"); $update = ($hour == "00000"); $File = "lastfriday.txt"; $start=file_get_contents($File); // Determine day of the week and the day's variable if($today == "Monday") { ($lastpage = $start + 1); } elseif($today == "Tuesday") { ($lastpage = $start + 2); } elseif($today == "Wednesday") { ($lastpage = $start + 3); } elseif($today == "Thursday") { ($lastpage = $start + 4); } // Looks like it's time to update! elseif($today == "Friday" && $hour == $update) { ($lastpage = $start + 5); $Handle = fopen($File, 'w'); $Data = "$lastpage"; fwrite($Handle, $Data); fclose($Handle); } elseif($today == "Friday") { $lastpage = $start; } //Whoops! It's the weekend! No change in the data for two days! elseif($today == "Sunday") { ($lastpage = $start); } elseif($today == "Saturday") { ($lastpage = $start); } echo $lastpage; ?> Link to comment https://forums.phpfreaks.com/topic/160294-write-file-not-working/#findComment-846367 Share on other sites More sharing options...
zerofool2005 Posted May 31, 2009 Share Posted May 31, 2009 EDIT: Ignore me Link to comment https://forums.phpfreaks.com/topic/160294-write-file-not-working/#findComment-846382 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.