Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

directory reading problem 1

Status
Not open for further replies.

Dweezel

Technical User
Joined
Feb 12, 2004
Messages
428
Location
GB
I'm trying to get this script to show me the contents of a directory on my remote server. The script is running without errors, and is pointing at the right directory.
There are no filenames of the files in the directory echoing to the browser. The space beetween the horizontal rules is just blank.
Any ideas why this may be happening?
Settings in php.ini perhaps?

<?php
$current_dir='/home/robhayes/public_html/uploads/';
$dir=opendir($current_dir);


echo "Upload directory is $current_dir <br>";
echo 'Directory Listing:<br><hr><br>';

while($file=readdir($dir));
{
echo "$file <br>";
}
echo'<hr><br>';


closedir($dir);


?>
 
hmm tried this on my machine here and it does not work.. suggest you try this from the php manual:
Code:
<?php
if ($handle = opendir('/path/to/files')) {
    echo "Directory handle: $handle\n";
    echo "Files:\n";

    /* This is the correct way to loop over the directory. */
    while (false !== ($file = readdir($handle))) { 
        echo "$file\n";
    }

    /* This is the WRONG way to loop over the directory. */
    while ($file = readdir($handle)) { 
        echo "$file\n";
    }

    closedir($handle); 
}
?>
 
That works perfectly. Thanks Moonspell.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top