Fetching multiple files from a Directory

Fetching multiple files from a Directory

Description

Displays a hyperlinked list of all the files contained in a specified folder. A simple way to have your own directory browser, just drop the file in the folder and it will show an index of all files in the directory on your webspace.

Sample code

<?

/**
* Change the path to your folder.
*
* This must be the full path from the root of your
* web space. If you’re not sure what it is, ask your host.
*
* Name this file index.php and place in the directory.
*/

// Define the full path to your folder from root
$path = “/home/user/public/foldername/”;

// Open the folder
$dir_handle = @opendir($path) or die(”Unable to open $path”);

// Loop through the files
while ($file = readdir($dir_handle)) {

if($file == “.” || $file == “..” || $file == “index.php” )

continue;
echo “$file”;

}

// Close
closedir($dir_handle);

?>

 

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.