IMC!


Contents


Photos

 







Browsing around...
News  News Links  Links Blog  Blog Italiano  Español 
List files and directories with link

This PHP function shows recursively a list of files and subdirectories in the given path. Every filename is also a link to the file. The function can be used, for example, to put online many files (such as docs or pdf) without using a database. You have only to put a file in the given path, and it will be automatically shown in the webpage containing this function. You can see it working in the Math, Electronics or Computer sections in this website.

Warning: The function uses some images, which should be in the directory foto. You can download the whole package here: elenco_dir.rar

Code of elenco_dir_en.php
<?PHP
# This funtion shows a tree list of files and subdirectories inside $base.
# Every name is a link to the file
# Copyright: Isacco Coccato - www.giacobbe85.altervista.org

# NOTES:
# - The path $base must not have / at the end.
# - Images for files and directories lists should be in "foto" directory.

function elenco_dir($base)
{
$dir_vuota=1# Flag for empty directory
if ($handle_dir opendir($base)) # Opens the directory and checks for the right path
{
    echo 
"<UL class=\"testo\">\n"
  while (
false!==($dir readdir($handle_dir))) # Reads an element and stores it in $dir
  
{
    if (
$dir!="." && $dir!=".."# Avoids "." and ".."
    
{
      
$dir_vuota=0;
          if(
is_dir($base"/" .$dir))
          {
           
# Code for directory
          
echo '<LI style="list-style-image: url(foto/cartella.gif)"><B>' $dir "</B>\n";
          
elenco_dir($base"/" .$dir); 
               echo 
"</LI>\n";
      }
       else
        {
          
# Code for file
            # Avoids to print some files
                # Prints files without extention, even if the extention has less or more than 3 letters, and the filename contains dots.
              
if ($dir != "." && $dir != ".." && $dir != "filename_not_to_be_shown.ext" && substr($dir,-3,3) != "extention_not_to_be_shown")
        {
                   echo 
'<LI style="list-style-image: url(foto/file.gif)"><A href="' .$base '/' $dir '">' str_replace('_'' 'substr($dir,0strrpos($dir,"."))) . "</A></LI>\n";
              }
      }
    }
  }
    if (
$dir_vuota==1) echo '<LI class="testo" style="list-style-image: url(foto/sbagliato.gif)">Nessun file presente</LI>';    
  echo 
"</UL><BR>";    
  
closedir($handle_dir);
}
else 
#Code for wrong path
{
  echo 
"Percorso errato";
}
}    

# Calls the function as example
elenco_dir(".");
?>






Fatal error: Call to undefined function sqlite_open() in /membri/giacobbe85/include/commenti.inc.php on line 324