Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Listar os arquivos de uma pasta Existe algum exemplo de como listar os arquivos de uma pasta e adicionar para seleção em um componente, para visualização? Eu tentei o TSortList, mas não obtive sucesso!...
MS
Listar os arquivos de uma pasta  
Fechado
Existe algum exemplo de como listar os arquivos de uma pasta e adicionar para seleção em um componente, para visualização?
Eu tentei o TSortList, mas não obtive sucesso!

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (5)


WJ

espero ter ajudado

  1. <?php
  2. $pasta 'imagens/'//NOME DA PASTA
  3.  if(is_dir($pasta)) //VERIFICA SE REALMENTE É UM DIRETORIO
  4. {
  5.   $diretorio dir($pasta); // LE O QUE TEM DENTRO DA PASTA
  6.         
  7.         $item = array();
  8.   while(($arquivo $diretorio->read()) !== false//LE ARQUIVO POR ARQUIVO
  9.   {
  10.    $item[$arquivo] =  $arquivo//CRIA A ARRAY COM DADOS QUE IRA SER EXIBIDA NA TSortList
  11.   }
  12.   $diretorio->close();
  13. }
  14.      $lista = new TSortList('nome_do_meu_campo'); //CRIA A TSortList        
  15.         $lista->addItems$item );//ADD ARRAY EM LISTA
  16. ?>
LC

Não sei se vai ajudar, mais neste exemplo: www.adianti.com.br/framework_files/tutor/index.php?class=FormInterac

tem TCombo::reload('form_interaction', 'response_b', $options); que alimenta uma combo, talvez de para adaptar ai.
MS

Obrigado,
foi exatamente o que buscava.
LJ

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

preciso de uma ajuda na linha 180 , quando apago um arquivo, ele apaga do diretorio, esta correto, porem não sei como recarregar a lista para não aparecer mais, tenho que sair e voltar.