Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Limpar a pasta appoutput Existe uma forma de limpar a pasta app/output Queria limpar os arquivos mais antigos, tipo mais de XX dias exclui os arquivos. Alguma dica ?...
LC
Limpar a pasta appoutput  
Fechado
Existe uma forma de limpar a pasta app/output
Queria limpar os arquivos mais antigos, tipo mais de XX dias exclui os arquivos.
Alguma dica ?

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (6)


RM

Boa noite. Sera que isso ajudaria?

php.net/manual/pt_BR/function.filemtime.php

Teria que ter um serviço que verificasse isso..
LC

É isso ai, usando esta dica sua, vou fazer assim:
  1. <?php
  2.             if ($handle opendir('app/output')):
  3.                 //echo "Manipulador de diretório: $handle <br>";
  4.                 echo "Arquivos: <br>";
  5.                 /* Esta é a forma correta de varrer o diretório */
  6.                 while (false !== ($file readdir($handle))):
  7.                     if ($file != '.' && $file != '..' && is_file("app/output/{$file}")):
  8.                         $hj = new DateTime();
  9.                         //var_dump($hj);
  10.                         $dataarq = new DateTimedate ("Y-m-d"filemtime("app/output/{$file}")) );
  11.                         //var_dump($dataarq);
  12.                         $intervalo $hj->diff$dataarq ); 
  13.                         //var_dump($intervalo);
  14.                         
  15.                         echo "$file " date ("d-m-Y H:i:s."filemtime("app/output/{$file}")) . "Intervalo é de {$intervalo->days} dias <br>";
  16.                         if ( $intervalo->days ):
  17.                             //unlink("app/output/{$file}");
  18.                         endif;
  19.                     endif;
  20.                 endwhile;
  21.                 closedir($handle);
  22.             endif;
  23. ?>
RM

É isso ai..show o/
LJ

fiz um programa para isso , faz algumas coisas a mais , mas é só apagar o que não necessita :
  1. <?php
  2. /**
  3.  */
  4. class PublicarInternoForm extends TPage
  5. {
  6.     private $form;     // registration form
  7.    
  8.     /**
  9.      * Class constructor
  10.      * Creates the page, the form and the listing
  11.      */
  12.     public function __construct()
  13.     {
  14.         parent::__construct();
  15.         
  16.         // creates the form
  17.         $this->form = new TForm('form_Fotografo');
  18.         $this->form->class 'tform'// CSS class
  19.         $this->form->style 'width: 500px';
  20.         
  21.         // creates a table
  22.         $table = new TTable;
  23.         $table-> width '100%';
  24.         $this->form->add($table);        
  25.         // add the table inside the form
  26.         
  27.         // create the form fields
  28.         $file = new TCombo('file');
  29.                 
  30.         //preenche o combo com os arquivos da pasta
  31.         $diretorio "app/output/";
  32.         $arquivos = array();
  33.         $i=1;
  34.     $ponteiro  opendir($diretorio);
  35.     // monta os vetores com os itens encontrados na pasta
  36.     while ($nome_itens readdir($ponteiro)) {
  37.             $itens[] = $nome_itens
  38.             }
  39.     sort($itens);
  40.     // percorre o vetor para fazer a separacao entre arquivos e pastas 
  41.     foreach ($itens as $listar)
  42.     {
  43.     // retira "./" e "../" para que retorne apenas pastas e arquivos
  44.        if ($listar!="." && $listar!="..")
  45.            { 
  46.         // checa se o tipo de arquivo encontrado é uma pasta
  47.            if (is_file($diretorio.$listar))
  48.                { 
  49.                $arquivos[$listar]=$listar;
  50.             $i++;
  51.             }
  52.         }
  53.     }    
  54.         $file->addItems($arquivos);
  55.         
  56.         
  57.         
  58.         // add a row for the field nome
  59.         $row=$table->addRow();
  60.         $row->class 'tformtitle'// CSS class
  61.         $row->addCell( new TLabel('Publica Arquivos Servidor') )->colspan 3;
  62.         
  63.         $table->addRowSet( new TLabel('Arquivo: '), $file);
  64.         $table->addRowSet" "," ");
  65.         
  66.         //cria botao de acao
  67.         $publica_button TButton::create('publica', array($this'onPublicarInternoSuaFoto'), 'Publicar-SUAfoto''ico_print.png');
  68.         $mostra_button TButton::create('mostra', array($this'onMostra'), 'Exibir''ico_print.png');
  69.         $excluir_button TButton::create('excluir', array($this'onExcluir'), 'Excluir''ico_print.png');
  70.         $download_button TButton::create('download', array($this'onDownload'), 'Download''ico_print.png');
  71.         
  72.     $buttons_box = new THBox;
  73.         $buttons_box->add($publica_button);
  74.         $buttons_box->add($mostra_button);
  75.         $buttons_box->add($excluir_button);
  76.         $buttons_box->add($download_button);
  77.         
  78.         // add a row for the form actions
  79.         $row=$table->addRow();
  80.         $row->class 'tformaction'// CSS class
  81.         $row->addCell($buttons_box)->colspan 3;
  82.         // define wich are the form fields
  83.         $this->form->setFields(array($file$publica_button,$mostra_button,$excluir_button,$download_button));
  84.         
  85.         parent::add($this->form);
  86.     }
  87.     
  88.     
  89.     function onPublicarInternoSuaFoto()
  90.     {
  91.         try
  92.         {
  93.             // open a transaction with database 'samples'
  94.             TTransaction::open('suafoto');
  95.             $conn TTransaction::get();   //obtem uma conexão
  96.             
  97.              // get the form data into an active record Book
  98.             $object $this->form->getData();
  99.             
  100.             if($object->file<>"")
  101.             {
  102.               $contador 0;
  103.                 $myfile fopen("app/output/".$object->file"r") or die("Unable to open file!");
  104.               while(!feof($myfile)) {
  105.             $querie fgets($myfile);
  106.                 if ($querie <>""){
  107.                     $result $conn->query($querie);
  108.                     $contador++;
  109.                     }    
  110.               
  111.             }
  112.         fclose($myfile);
  113.             
  114.   
  115.             
  116.             new TMessage('info','Banco atualizado com sucesso '.$contador);
  117.             }else{
  118.             new TMessage('info','Escolha um  arquivo');
  119.             }
  120.           
  121.             // close the transaction
  122.             TTransaction::close();
  123.         }
  124.         catch (Exception $e// in case of exception
  125.         {
  126.             // shows the exception error message
  127.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  128.             // undo all pending operations
  129.             TTransaction::rollback();
  130.         }
  131.     }
  132.     
  133.     
  134.     function onMostra()
  135.     {
  136.         $object $this->form->getData();
  137.         if($object->file<>"")
  138.             {
  139.             $this->form->setData($object);
  140.         
  141.             $scroll = new TScroll;
  142.             $scroll->setSize(640460);
  143.             $scroll->style 'padding: 4px; border-radius: 4px;';
  144.     
  145.         
  146.             $source = new TSourceCode;
  147.             $source->loadFile("app/output/".$object->file);
  148.             $scroll->add($source);
  149.         
  150.             // wrap the page content
  151.             $vbox = new TVBox;
  152.             $vbox->add($scroll);
  153.             parent::add($vbox);
  154.             }
  155.     
  156.     }
  157.     function onExcluir()
  158.     {
  159.         try
  160.         {
  161.         $object $this->form->getData();
  162.         // define the delete action
  163.         //$action = new TAction(unlink("app/output/".$object->file));
  164.         //$action->setParameters($param); // pass the key parameter ahead
  165.         unlink("app/output/".$object->file);
  166.         // shows a dialog to the user
  167.         new TMessage('info','Arquivo excluido');
  168.         //new TQuestion('Confirma a EXCLUSÃO ?', $action);
  169.         }
  170.         catch (Exception $e// in case of exception
  171.         {
  172.             // shows the exception error message
  173.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  174.             // undo all pending operations
  175.             TTransaction::rollback();
  176.         }  
  177.         //preenche o combo com os arquivos da pasta
  178.         $diretorio "app/output/";
  179.         $arquivos = array();
  180.         $i=1;
  181.     $ponteiro  opendir($diretorio);
  182.     // monta os vetores com os itens encontrados na pasta
  183.     while ($nome_itens readdir($ponteiro)) {
  184.             $itens[] = $nome_itens
  185.             }
  186.     sort($itens);
  187.     // percorre o vetor para fazer a separacao entre arquivos e pastas 
  188.     foreach ($itens as $listar)
  189.     {
  190.     // retira "./" e "../" para que retorne apenas pastas e arquivos
  191.        if ($listar!="." && $listar!="..")
  192.            { 
  193.         // checa se o tipo de arquivo encontrado é uma pasta
  194.            if (is_file($diretorio.$listar))
  195.                { 
  196.                $arquivos[$listar]=$listar;
  197.             $i++;
  198.             }
  199.         }
  200.     }
  201.         // preciso de uma forma de recarregar a pagina ou remover este item do $file
  202.     TCombo::reload('form_Fotografo''file',$arquivos);
  203.         
  204.    }
  205.    function onDownload()
  206.    {
  207.         $object $this->form->getData();
  208.         $file="app/output/".$object->file;
  209.         parent::openfile($file);
  210.    
  211.    }
  212. }
  213. ?>

PD

unix.stackexchange.com/questions/136804/cron-job-to-delete-files-old
ST

Obrigados a todos pela ajuda.
Problema resolvido.