• BOOKMARK

  • ADD TO FAVORITES

  • REFERENCES


  • MARC

    Mailing list ARChives
    - Search by -
     Subjects
     Authors
     Bodies





    FOLDOC

    Computing Dictionary




  • Text Link Ads






Gettting a Directory Listing

PHP Tutorials.

Gettting a Directory Listing

New postby Ranman on Thu Mar 27, 2008 10:34 pm

Code: [Select all] [Expand/Collapse] [Download] (Untitled)
# Here are two examples of reading directorys. The first gets
# a simple directory listing. The second gets all files and
# directory that end with 'gif'.
#
# The @ in front of the opendir() will suppress, if any, a PHP
# error warning from, in this case, opendir() and just print
# the "Unable to open $path" message to the web browser if the
# directory doesn't exsist for example.

<html><body><?
$path = '/usr';
$dir_handle = @opendir($path) or die("Unable to open $path");
echo "Directory Listing of $path<BR>";
while ($file = readdir($dir_handle)) {
        echo "$file<br>";
}
closedir($dir_handle);

$path = 'images/';
$dir_handle = @opendir($path) or die("Unable to open $path");
echo "Directory Listing of $path<BR>";
while($file = readdir($dir_handle)) {
  if (substr($file, -3) == 'gif') {
    echo "$file<br>";
} }
closedir($dir_handle);
?></body></html>
User avatar
Ranman
Site Admin
 
Posts: 25
Joined: Thu Mar 27, 2008 12:27 am

Return to PHP Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

  • MORE RESOURCE


  • Linux

    The Distributions





    Linux

    The Software





    Linux

    The News



  • MARKETING






  • Toll Free
cron