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
https://forums.phpfreaks.com/topic/54018-solved-time-limit-to-delete-from-mysql/
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");
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.