graham23s Posted June 2, 2007 Share Posted June 2, 2007 Hi Guys, on my site i allow users to upload .doc, .pdf and image files, over time these files will build up on the server and take up a bit of space, i was thinking of adding a "clean up" button in the admin section where files/users older than a certain time are deleted from mysql and the files (unlinked) can anyone advise me on the best way to acomplish this. i know i need to query the database then find all files uploaded (say after 28 days for example) is that on the right track or is there another way at all? thanks guys Graham Quote Link to comment https://forums.phpfreaks.com/topic/54018-solved-time-limit-to-delete-from-mysql/ Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 personally... i'd only allow files to last for 1 day... so... $day=date(z); $query=mysql_query("SELECT * FROM `files` WHERE day!='$day'"); while($row=mysql_fetch_assoc($query)){ unlink($row[filepath]); mysql_query("DELETE FROM `files` WHERE `id`='$row[id]' LIMIT 1"); } Quote Link to comment https://forums.phpfreaks.com/topic/54018-solved-time-limit-to-delete-from-mysql/#findComment-267069 Share on other sites More sharing options...
graham23s Posted June 2, 2007 Author Share Posted June 2, 2007 Hi Taith, would the process of deleteing users just be pretty much the same but delete from the `membership` table? what would the syntax to work out say 28 days in mysql be at all? thanks mate Graham Quote Link to comment https://forums.phpfreaks.com/topic/54018-solved-time-limit-to-delete-from-mysql/#findComment-267080 Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 yup! just find the ones that are past the expirey dates, pull them into the loop, delete all relevent information from all your tables/files, delete user, can even send em an email if you want :-) telling them the account has gone poof :-) Quote Link to comment https://forums.phpfreaks.com/topic/54018-solved-time-limit-to-delete-from-mysql/#findComment-267089 Share on other sites More sharing options...
graham23s Posted June 2, 2007 Author Share Posted June 2, 2007 excellent, i thought it was gonna be harder than that for some reason lol thanks again mate Graham Quote Link to comment https://forums.phpfreaks.com/topic/54018-solved-time-limit-to-delete-from-mysql/#findComment-267097 Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 many people do make it harder... lol... i like not to over complicate my code ;-) lol Quote Link to comment https://forums.phpfreaks.com/topic/54018-solved-time-limit-to-delete-from-mysql/#findComment-267105 Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 if you do want to set a date(z)-30 exipery date... remember about january... if($date<0) $date+=364; as it counts 0-364(non leap year withstanding, but if its leap year, feburary wouldnt get caught by it...) Quote Link to comment https://forums.phpfreaks.com/topic/54018-solved-time-limit-to-delete-from-mysql/#findComment-267107 Share on other sites More sharing options...
graham23s Posted June 2, 2007 Author Share Posted June 2, 2007 ah i see, i'm getting the hang of this a lot better now (i take a lot of notes in a blank programming book lol). thanks for the help and tips mate Graham Quote Link to comment https://forums.phpfreaks.com/topic/54018-solved-time-limit-to-delete-from-mysql/#findComment-267171 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.