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 Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


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

PD

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

Obrigados a todos pela ajuda.
Problema resolvido.