Jump to content

Is it possible to auto delete image after a certain time?


phpnoobie9

Recommended Posts

yes/no

 

Since it needs to be called via the execution of a php script you lose the ability to make a continous function

However you can build something that will autoload via CRON or each page load that will do it

 

look around php.net for how to read the file dates.

As an alternative if you don't have access to cron

 

Include a snippet/function in you main class contruct or included header file that finds files older than x date and removes them. If this is going to be a process-consuming function, or you expect to have lots of traffic, randomize and create a % chance of happening... or simply track the last time it was cleaned in a flat file, and have the function check against a set time and clean and update the flat file with the current date

 

Let the users activate the 'cron' for you :)

As an alternative if you don't have access to cron

 

Include a snippet/function in you main class contruct or included header file that finds files older than x date and removes them. If this is going to be a process-consuming function, or you expect to have lots of traffic, randomize and create a % chance of happening... or simply track the last time it was cleaned in a flat file, and have the function check against a set time and clean and update the flat file with the current date

 

Let the users activate the 'cron' for you :)

 

Where will I start if I want to make a script that deletes images in a certain directory older than x amount of time...as far as using a function?

Delete files within a directory x time.........

 

just adapt the code ok.

<?php
        function cleantmp() {
                $seconds_old = 3600;
                $directory = "/var/tmp";

                if( !$dirhandle = @opendir($directory) )
                        return;

                while( false !== ($filename = readdir($dirhandle)) ) {
                        if( $filename != "." && $filename != ".." ) {
                                $filename = $directory. "/". $filename;

                                if( @filemtime($filename) < (time()-$seconds_old) )
                                        @unlink($filename);
                        }
                }
        }
?>

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.