Displaying files, but hiding subdirectories

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Displaying files, but hiding subdirectories

Post by tristanlee85 »

Code: Select all

<?php
$folder = "\\saturnspot";
$link = 'http://24.197.74.135/saturnspot';
if ($handle = opendir($folder)) { 
   while (false !== ($file = readdir($handle))) { 
       if ($file != "." && $file != "..") { 
           echo "<a href="http://24.197.74.135/saturnspot/$file">$file</a><br><br>"; 
       } 
   } 
   closedir($handle); 
} 
?>
With this, it shows all files and folder in the folder specified. How do I display only files and hide the folders?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

//....[skipped]....
      if ($file != "." && $file != ".." && !is_dir($folder.$file)) {
//....[skipped]....
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Ahh, thank you.
Post Reply