lional Posted September 24, 2008 Share Posted September 24, 2008 Hi All I am writing a site where files are uploaded. I dont want the webspace to be filled with previous images that were uploaded so what I want to do is delete files that were uploaded 2 days ago. I am storing the date of each uploaded file in a mysql database in the form yyyy-mm-dd. How would I accomplish this Regards Lional Quote Link to comment https://forums.phpfreaks.com/topic/125644-deleting-files/ Share on other sites More sharing options...
.josh Posted September 24, 2008 Share Posted September 24, 2008 Select all files from db with date older than 2 days, use unlink() on each one, with a loop. Now setup a cron job to run the script however often you want. Quote Link to comment https://forums.phpfreaks.com/topic/125644-deleting-files/#findComment-649617 Share on other sites More sharing options...
lional Posted September 24, 2008 Author Share Posted September 24, 2008 I understand that but how do I select the days backward. say the date is the 1st of the month, how will I tell it if it is the 31st, 30th etc Quote Link to comment https://forums.phpfreaks.com/topic/125644-deleting-files/#findComment-649622 Share on other sites More sharing options...
.josh Posted September 24, 2008 Share Posted September 24, 2008 I'm not a sql expert but you can do something like this (I think...): SELECT * FROM table WHERE datecol < DATE_SUB(CURDATE(),INTERVAL 2 DAY) Quote Link to comment https://forums.phpfreaks.com/topic/125644-deleting-files/#findComment-649641 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.