Ir para conteúdo
Fórum Script Brasil
  • 0

Listar Diretorio


onsguitar

Pergunta

IAE Galera !

to com um probleminha.

Estou com um código PHP para Listar todos os arquivos de um diretorio FTP até aki OK

o problema é que ele só LISTA os arquivos do Diretorio que ele esta Exemplo

DIRETORIO:

HTM -->

Listar.php

foto.jpg

ARQUIVOS:

atas.pdf

foto01.jpg

Eu queria que ele listasse os arquivos do Diretorio ARQUIVOS

Eis o Código

<?php  


 function varSet($VAR) { return isset($_GET[$VAR]) ? $_GET[$VAR] : ""; }  

 $action = varSet("action");  

 $pasta = base64_decode(varSet("pasta"));  

    

 //Lista dos arquivos que não serão listados  
 $denyFiles = array(".htaccess","thumbs.db");  

    

 if ($action == "download") {  

     $file = base64_decode(varSet("file"));  

     header("Content-disposition: attachment; filename=\"".basename($file)."\"");  

     readfile(".$file");  

     exit;  
 }  
 ?>  
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  

 <html xmlns="http://www.w3.org/1999/xhtml">  

 <head>  

 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />  

 <title>Listagem de Arquivos</title>  

 <style type="text/css">  

 body {  

     font:11px Verdana, Arial, Helvetica, sans-serif;  

     padding:0px;  

    margin:0px;  

 }  
 a {  

     text-decoration:none;  

     color:#003366;  

 }  

 a:hover { color:#0099CC }  

 .row1 { background-color:#F7F7F7 }  

 .row2 { background-color:#EBEBEB }  

 .rowOver { background-color:#C7DCFC }  

 .extCell { font-weight:bold }  

 </style>  

 &lt;script language="javascript" type="text/javascript">  

 function over(Obj) {  

     nClass = Obj.className  

    Obj.className = "rowOver" 

     Obj.onmouseout = function() {  

         Obj.className = nClass  

    }  

 }  

 </script>  

 </head>  

    

 <body>  
 <?php  

 if ($action == ""):  

 $fdir = "./$pasta";  

 chdir($fdir);  

 $dir = opendir(".");  

 while ($file = readdir($dir)) if (is_dir($file)) $dirs[] = $file; else $files[] = $file;  

 $row = 2;  

 ?>  

 <table width="700" border="0" align="center" cellpadding="0" cellspacing="0">  

   <tr>  

     <td height="50px;"> <div align="center">Abra ou faça o Download dos Arquivos
       Abaixo</div></td>  

   </tr>  

   <tr>  

     <td height="50px;"><strong>Exibindo:</strong> Arquivos <?php echo empty($pasta) ? "" : $pasta; ?></td>  

   </tr>  

 </table>  

 <table width="700" border="0" align="center" cellpadding="0" cellspacing="0">  

   <tr style="font-weight:bold">  

     <td width="55" height="20"> </td>  

     <td width="204">Nome</td>  

     <td width="130">Tamanho</td>  

     <td width="316">Ações</td>  

   </tr>  
 <?php if ($pasta != ""): ?>  

   <tr class="row<?php echo $row; ?>" onmouseover="over(this)">  

     <td align="center" width="55" height="20" class="extCell">[DIR]</td>  

     <td><a href="?pasta=<?php echo base64_encode(substr("$pasta",0,strrpos($pasta,"/"))); ?>">..</a></td>  

     <td>--</td>  

     <td> </td>  
   </tr>  

 <?php endif; ?>  

 <?php  

 if (is_array($dirs)) :  

     sort($dirs);  

     foreach ($dirs as $nome):  

     if ($nome == ".." || $nome == ".") continue;  

     if ($row == 2) $row = 1; else $row = 2;  

 ?>  

   <tr class="row<?php echo $row; ?>" onmouseover="over(this)">  

     <td align="center" width="55" height="20" class="extCell">[DIR]</td>  

     <td><a href="?pasta=<?php echo base64_encode("$pasta/$nome"); ?>"><?php echo $nome; ?></a></td>  
     <td>--</td>  
     <td> </td>  
  </tr>  

 <?php  

     endforeach;  
 endif;  

 ?>  
 <?php  

 if (is_array($files)):  

     sort($files);  

     foreach ($files as $nome):  

     if (in_array(strtolower($nome),$denyFiles)) continue;  

     if ($row == 2) $row = 1; else $row = 2;  

    $tamanho = filesize("./$nome");  
     $info = pathinfo("./$nome");  

 ?>  
   <tr class="row<?php echo $row; ?>" onmouseover="over(this)">  

    <td align="center" width="55" height="20" class="extCell">[<?php echo strtoupper($info["extension"]); ?>]</td>  

     <td>  

 <a href="?action=download&file=<?php echo base64_encode("$pasta/$nome"); ?>"><?php echo $nome; ?></a>  

     </td>  

     <td><?php echo $tamanho > 1048576 ? round($tamanho/1048576,2)." Mb" : round($tamanho/1024,2)." Kb"; ?></td>  

    <td> </td>  

   </tr>  

 <?php  

     endforeach;  

 endif;  
 ?>  
 </table>  
 <?php endif; ?>  
 <p align="center"><a href="../index.php">Enviar mais Arquivos</a></p>
 <p align="center"><a href="../../index.html">Home</a></p>
 </body>  
 </html>  
 <?php closedir($dir); ?>

Link para o comentário
Compartilhar em outros sites

5 respostass a esta questão

Posts Recomendados

  • 0
você sabia que você pode acessar um diretório anterior assim ../ ? Exemplo include_once '../supFolder/file.ext'; Para referenciar um mesmo diretório use ./folder/file.ext, ou apenas folder/file.ext.

Rafa, não funcionou. poderia me dar um exemplo em codigo?

tipo, minha estrutura esta dessa forma:

/RAIZ

/RAIZ/WWW/ (AREA DA INTERNET)

/RAIZ/FILES/PASTAS/ (ONDE ESTAO OS ARQUIVOS)

DO WWW, EU CONSIGO LISTAR, POREM não CONSIGO DAR DOWNLOAD NOS ARQUIVOS.

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...