Jump to content

[SOLVED] Time Limit To Delete From Mysql


graham23s

Recommended Posts

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

Link to comment
Share on other sites

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");
}

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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 :-)

Link to comment
Share on other sites

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...)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.