Deleting Refuse (Old Files) Server

Results 1 to 2 of 2
  1. #1
    Member Makloud is offline
    MemberRank
    Apr 2008 Join Date
    BRLocation
    53Posts

    thumbs up Deleting Refuse (Old Files) Server

    With this function you can delete very old server, things are no longer used, and this means the panel, which can add on a panel for example adm.
    The date is counted last updated the file has.

    PHP Code:
    <?php

    //$diretorio : nome da pasta que deseja limpar arquivos lixo
    //$arquivos: quais os tipos de arquivo deseja apagar. Use: * (para todos) ou  *.txt (todos os .txt)
    //$dias: indique o número de dias que deseja apagar que sejam antigos.

    function apagalixo($diretorio,$arquivos,$dias) {
    foreach(
    glob("$diretorio/$arquivos") as $file) {
    if(
    filemtime($file) < strtotime("-$dias days")) {
    if(
    unlink($file)) {
    echo 
    "<b>".basename($file)."</b> foi removido com sucesso.<br>";
    // unlink
    // filemtime
    // foreach
    // apagalixo

    apagalixo("diretorio""*""1"); // Nesse exemplo estamos apagando todos os arquivos com 1 dia sem uso da pasta diretorio
    ?>
    Last edited by DarkKnightH20; 27-01-10 at 09:37 AM.


  2. #2
    Omega bobsobol is offline
    MemberRank
    May 2007 Join Date
    UKLocation
    5,702Posts

    Re: Deleting Refuse (Old Files) Server

    Nice... if you use this a lot, can you give us an idea of how old is safe to remove? I run a similar script (not PHP) on an automated backup schedule setting to move .itm files over a month old once a month to a Zip named by the backup date.

    So items dropped are never kept in the dropitem folder more than two months, but can be restored... this is more general, (read powerful) but doesn't perform backup, (read dangerous) as I see it. Nice work though.



Advertisement