graham23s Posted July 11, 2007 Share Posted July 11, 2007 Hi Guys, using this code i delete files older than 45 days on my server: <?php error_reporting(0); $number_of_days = 45; // using UNIX timestamp in the table...///////////////////////////////////////////// $stamp = strtotime("-".$number_of_days." day"); // using MySQL DATETIME...////////////////////////////////////////////////////////// $stamp = date('Y-m-d H:i:s', strtotime("-".$number_of_days." day")); $result = $result = mysql_query("SELECT * FROM `uploaded_files` WHERE `date_added` <= '$stamp'"); while ($row = mysql_fetch_array($result)) { $file = $row['doc_file']; unlink("docs/$file"); // remove files...////////////////////////////////////////////////////////////////// } mysql_query("DELETE FROM `uploaded_files` WHERE `date_added ` <= '$stamp'"); // if everything went ok...///////////////////////////////////////////////////////// if($result) { echo'<br /><b>Thank You, All Files Older Than 45 Days Have Been Deleted!</b><br /><br />'; } else { echo '<br /><b><font color="red">Error:</font> Sorry There Was An Unexpected Error Purging The System!</b><br /><br />'; } ?> This works great it deletes the actual files on the server after 45 days , but theres also information associated with the files in mysql aswell like comments made when uploaded, the id , date uploaded etc i really need that deleted aswell , along with the files what would be the best way to alter the code to do this? thanks for any help Graham Quote Link to comment 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.