Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Two possible solutions :</p> <ul> <li>You could loop over the files on the disk, testing the last modification time for each one of them -- and delete the oldest ones. <ul> <li>A first solution would be to work with <a href="http://fr2.php.net/opendir" rel="nofollow"><code>opendir()</code></a>/<a href="http://fr2.php.net/manual/en/function.readdir.php" rel="nofollow"><code>readdir()</code></a>/<a href="http://fr2.php.net/manual/en/function.closedir.php" rel="nofollow"><code>closedir()</code></a>, and <a href="http://fr2.php.net/filemtime" rel="nofollow"><code>filemtime()</code></a>.</li> <li>Another idea would be to work with iterators : <a href="http://fr2.php.net/manual/en/class.directoryiterator.php" rel="nofollow"><code>DirectoryIterator</code></a> or <a href="http://fr2.php.net/manual/en/class.recursivedirectoryiterator.php" rel="nofollow"><code>RecursiveDirectoryIterator</code></a>, and <a href="http://fr2.php.net/manual/en/splfileinfo.getmtime.php" rel="nofollow"><code>SplFileInfo::getMTime()</code></a>.</li> </ul></li> <li>Or, you could use a database, and : <ul> <li>Add a row to it each time a file is uploaded, containing the current time and date</li> <li>And use that database to determine which file are old enough to be deleted.</li> </ul></li> </ul> <p><br> The second idea is probably better than the first one : </p> <ul> <li>Yes, it means a bit more work right now, when you have to code the system</li> <li>But, if you have lots of files, going through all of them to find the old ones, with the first solution, will not be fast -- and might slow down your server for a while, when the disks are working, seeking for files.</li> </ul> <p><br> Note that the first solution could be enhanced quite a bit :</p> <ul> <li>Use a different folder for each day and hour <em>(<code>2011-04-10-10</code>, <code>2011-04-11</code>, <code>2011-04-10-12</code>, ...)</em></li> <li>And, then, only delete the directories <em>(and their content)</em> which are old enough</li> </ul> <p>With that, no need to search for files : just search for a couple of directories.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload