HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

remove uploaded attachments older then 30 days

jackmaessenjackmaessen ✭✭✭
edited March 2015 in General Banter

I am experimenting with this piece of code to automatically remove files (uploaded files like attachments) when they are older then 30 days.

<?php

/*** folder to files ***/
$dir = "uploads/test/";

/*** loop through all the files in the folder ***/
foreach (glob($dir."*") as $file) {

/*** if files older then 30 days after upload; -> remove ***/
if (filemtime($file) < time() - 60*60*24*30) { // 30 days
    unlink($file); // remove
    }
}

?>

Only thing i don't know how to handle with is the attachment links in the comments; they are still there and they become dead links.
So i have to think of a way how to remove also automatically the links in the comments...

Tagged:

Comments

Sign In or Register to comment.