Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Ribamar FS http://ribafs.net

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Directory List with PHP

// description of your code here

This code list all files and subdirectories in a dirctory with links.

   1  
   2  
   3  <html><head><title>ribafs.net - Tutoriais</title></head>
   4  <body bgcolor='#FFFACD'>
   5  <h2 align=center><a href="http://ribafs.net">http://ribafs.net - <?php echo date('d/m/Y H:i:s'); ?></a></h2>
   6  
   7  <?php
   8  $dn = opendir (dirname(__FILE__));
   9  $exclude = array("index.php", ".", "..");
  10  
  11  // adiciona os arquivos ao array $arquivos
  12  while($fn = readdir($dn)) {
  13  	if ($fn == $exclude[0] || $fn == $exclude[1] || $fn == $exclude[2]) continue;
  14  	$arquivos[] = $fn;
  15  }
  16  // ordena o vetor
  17  sort($arquivos);
  18  // exibe os arquivos
  19  
  20  foreach ($arquivos as $arquivo)
  21  
  22  if (is_dir($arquivo)){
  23  	$dir .= "<img src='/imagens/diretorio.png'>&nbsp;<a href='$arquivo'>$arquivo</a><br>";
  24  }else{
  25  	$tamanho = filesize($arquivo);
  26  	$m = 'bytes';
  27  	if ($tamanho>1024) {
  28  		$tamanho=round($tamanho/1024,2);
  29  		$m = 'KB';
  30  	} elseif($tamanho > 1024*1024){
  31  		$tamanho = round(($tamanho/1024)/1024,2);
  32  		$m = 'MB';
  33  	}
  34  	$arq .= "<img src='/imagens/arquivo.png'>&nbsp;<a href='$arquivo'>$arquivo</a> - $tamanho $m<br>";
  35  }
  36  echo $dir . $arq;
  37  
  38  closedir($dn);
  39  ?>
  40  
  41  
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS