Rated an average of 4 stars by 1 person

List Files in Directory

Script Details:
Added on February 3, 2011 by Zhay. Last modified February 3, 2011.
Zhay accreditted the script to "php.net documentation."

Description:
This code prints out all of the files in the given directory.

Tags: current, directory, filenames, files, list, output, print

Instructions:
<?php
list_files();
// or
list_files('uploads/');
?>

Code:

<?php
# Snippet from PHP Share: http://www.phpshare.org

function list_files($directory '.')
{
    if (
$directory != '.')
    {
        
$directory rtrim($directory'/') . '/';
    }
    
    if (
$handle opendir($directory))
    {
        while (
false !== ($file readdir($handle)))
        {
            if (
$file != '. '& &$file != '.')
            {
                echo 
'..'$file'';
            }
        }
        
        
closedir($handle);
    }
}
?>

Review this PHP Script:

Rating:

Comments:


Login

User:
Pass:

Register

Not a member? Register today and receive the many free benefits of being a member!

Advertisements