Iki Posted July 8, 2006 Posted July 8, 2006 Hi all, Need some input on where to start with this. I've got a nightly CRON job set up that refers to a PHP file that goes through my database and deletes any entries that are over 10 days old. What I'd like it to do is write to a file how many entries were deleted. I'd like it to append the information to the end of the file so I'd have a running record of what was deleted each night. Eventually I'd like it to put today's date in the file, the titles of the entries over 10 days old, and then a confirmation line that those were deleted. For instance, I'd like the file to say something like: 2006-07-02: Entry Title1 Entry Title2 Entry Title3 Total of 3 entries deleted 2006-07-03: Entry Title4 Entry Title5 Total of 2 entries deleted 2006-07-04: Entry Title6 Entry Title7 Entry Title8 Entry Title9 Total of 4 entries deleted I can pull today's date and the entry titles that will be deleted out of the database, and then run the mysql delete command to get rid of them. I mean, I can set up the script to output this information in this format - what I'm not getting is how to send that information to a file. I'm guessing from my research so far I'll need to use fopen() to do it, but the examples I'm finding are WAY too complicated for my pea brain to process. Anyone got a sample SIMPLE fopen() example? Quote
Dman8568 Posted July 10, 2006 Posted July 10, 2006 (edited) For what you are wanting to do it use a combination of fopen, fwrite, and fclose. Here is a very basic example: >// This example asumes you have whatever you want to be writen to the file in a variable named "$data" // Also, your target file needs be CHMOD 0777 (or you will get an error back) // Open Connection to Target File $handle = fopen("[Filename]", "a"); // the "a" is the mode, a = "open for writing, place start position at END of file // Write Data to file fwrite ($handle, $data); // Close Connection fclose($handle); Referances for each function: fopen:http://us2.php.net/manual/en/function.fopen.php fwrite:http://us2.php.net/manual/en/function.fwrite.php fclose:http://us2.php.net/manual/en/function.fclose.php I hope this helps Edited July 10, 2006 by Dman8568 Quote
Iki Posted July 10, 2006 Author Posted July 10, 2006 Perfect, thanks! The submitted code bits in the online manual are all waaaaaayyyy more complicated than I needed to get me started, and surprisingly the O'Reilly Programming PHP book doesn't even address fopen except from a security standpoint. Thanks again for the example! Quote
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.