WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : List directory content - ftp explorer using a simple php code
Categories : PHP, FTP, Filesystem Click here to Update Your Picture
Andrei R.
Date : Sep 24th 2006
Grade : 4 of 5 (graded 8 times)
Viewed : 20892
File : 4502.rar
Images : No Images for this code example.
Search : More code by Andrei R.
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

- the code lists the content of a folder (files and subfolders), lets you navigate in a similar manner to explorer (you can enter subfolders, view images, download files)
- i also added some basic html / css, so that you can install and use it directly

<!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>Ftp Explorer .::. Download page</title>
<style type="text/css">
<!--
body {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 11px;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    color: #333333;
    text-decoration: none;
    padding: 20px;
}
img {
    border: 0px;
}
a {
    color: #333333;
    text-decoration: none;
}
a:hover {
    color: #0066FF;
}

-->
</style>
</head>
<body>

<?

// install variables

   
$host = "http://www.orosandrei.ro/download/"; // the folder where index.php is located
    // path for folder, file, buttons(back and home) images
   
$img_back="http://www.orosandrei.ro/images/back.gif";
   
$img_folder="http://www.orosandrei.ro/images/folder.gif";
   
$img_file="http://www.orosandrei.ro/images/file.gif";
   
$img_home="http://www.orosandrei.ro/images/home.gif";

// end of install variables


// returns the extension of a file
function strip_ext($name)
{           
         
$ext = substr($name, strlen($ext)-4, 4);
           if(
strpos($ext,'.') === false) // if we have a folder element
           
{
               return
"    "; // we return a string of space characters for later sort,
                             // so that the folder items remain on the first positions
           
}
           return
$ext; // if we have a file we return the extension - .gif, .jpg, etc.
}



// returns the files from the $path and returns them in an array
function getFiles($path) {

   
$files = array();
   
$fileNames = array();
   
$i = 0;
   
// build
   
if (is_dir($path)) {
       if (
$dh = opendir($path)) {
           while ((
$file = readdir($dh)) !== false) {
               if ((
$file == ".") || ($file == "..")) continue;
               
$fullpath = $path . "/" . $file;
               
//$fkey = strtolower($file);
               
$fkey = $file;
               while (
array_key_exists($fkey,$fileNames)) $fkey .= " ";
               
$a = stat($fullpath);
               
$files[$fkey]['size'] = $a['size'];
               if (
$a['size'] == 0) $files[$fkey]['sizetext'] = "-";
               else if (
$a['size'] > 1024 && $a['size'] <= 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
               else if (
$a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
               else
$files[$fkey]['sizetext'] = $a['size'] . " bytes";
               
$files[$fkey]['name'] = $file;
               
$e = strip_ext($file); // $e is the extension - for example, .gif
               
$files[$fkey]['type'] = filetype($fullpath); // file, dir, etc
               
$k=$e.$file; // we use this string for sorting the array elements by extension and filename;
               
$fileNames[$i++] = $k;
           }
           
closedir($dh);
       } else die (
"Cannot open directory:  $path");
   } else die (
"Path is not a directory:  $path");
   
sort($fileNames,SORT_STRING); // sorting
   
$sortedFiles = array();
   
$i = 0;
   foreach(
$fileNames as $f) {
           
$f = substr($f, 4, strlen($f)-4); // we remove the extension we added in front of the filename for sorting
           
if($files[$f]['name'] !='') $sortedFiles[$i++] = $files[$f];   
    }
// ends the foreach where we build the final sorted array
   
return $sortedFiles;
}


// folder navigation code
$startdir = "./";
if(isset(
$_GET['dir'])) {
   
$prev = $_GET['dir'];
   
$folder = $_GET['dir'];   
    echo
"<a href=\"javascript:history.go(-1)\"><img src=\"$img_back\"></a>   <a href=\"$host\"><img src=\"$img_home\"></a> <br/><br/>";
} else {
$folder = $startdir; $prev='';}
// end folder navigation code


$files = getFiles($folder);

foreach (
$files as $file) {
    if(
strip_ext($file[name])!='.php'){
       
$image = $img_file;
        if(
$file[type]=='dir') {
           
$image = $img_folder;
           
$cmd='?dir='.$prev.$file[name].'/';
        }
// if the element is a directory
       
else $cmd=$prev.$file[name];
        echo
"<a href=\"$cmd\" title=\"$file[type]$file[sizetext]\"><img src=\"$image\" /> $file[name]</a> <br/>";
    }
//if strip_ext
}//foreach
?>

</body>
</html>



Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support
Categories : PHP, FTP, Filesystem, PHP Classes, Compression
Directory TreeView - File Manager & Explorer - FTP - Utility - PHP/HTML -
Categories : PHP, Directories, FTP, Filesystem, HTML and PHP
Upload function using PHP's FTP abilities.
Categories : PHP, Filesystem, FTP
Moving folder hierarchy b/w server
Categories : PHP, FTP, Filesystem
A PHP Script that shows how to use FTP to run a shell script, read two local files and update data in a database.
Categories : PHP, Filesystem, FTP, Date Time, Databases
Fetching product details from the commission junction website using php
Categories : PHP, FTP, Filesystem, Compression
Using PHP to Delete a directory with all sub directories and files using FTP
Categories : PHP, FTP, Directories, Filesystem
filesplit : Split big text files in multiple small ones
Categories : PHP, Log Files, Filesystem, PHP Classes
A File Browser Class.To Read Drives,Directories and Files .Files writing is also possible
Categories : PHP, PHP Classes, Filesystem
Link Submition - Allow your visitors to submit links to the site.
Categories : PHP, Arrays, Filesystem, Beginner Guides
Upload Via FTP - an alternative to move_uploaded_file
Categories : PHP, FTP, Beginner Guides
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Bs_IniHandler is a class that can read and write ini-style files (and strings)
Categories : PHP, Filesystem, PHP Classes
List the content of the directory of your webserver where this small PHP Script resides.
Categories : PHP, Filesystem, Directories, CSS
Remote File Saving with PHP - Download and serve a remote file. The content of the file will be updated at fixed intervals.
Categories : PHP, Filesystem, Cache, Sockets, HTTP
 Murray Matson wrote :1858
I think there is a logic error in the line:
     if($files[$f]['name'] !='') $sortedFiles[$i++] = $files[$f];

Maybe I'm missing something but the array $sortedFiles[] contains nothing
but the string "Array" in every cell.

I think that it should be:
if($files[$f]['name'] !='') $sortedFiles[$i++] = $f;