Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Folder view works but can the output be formatted?

    Hi all,

    I've got this script working and it displays the contents of the folder.

    I was wondering if someone could show me what I need to add to hide .php files from being displayed?

    Code:
    <?php
    $dir = "http://mysite.com/files/uploads/";
    
    // Open a known directory, and proceed to read its contents
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
                echo "filename: $file : filetype: " . filetype($dir . $file) . "/n";
            }
            closedir($dh);
        }
    }
    
    if ($handle = opendir('.')) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                echo "$file<br />";
            }
        }
        closedir($handle);
    }
    ?>
    I am really new to php and I'm trying to piece things together so if you could provide and example that would be of a great help.

    Thanks
    TT
    Last edited by toxictoad; 12-08-2008 at 01:46 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    There are a number of ways to do this. I'll be using pathinfo with a PHP5+ option identifier:
    PHP Code:
    $aHideExt = array(
        
    'php'
    );
    if (
    $handle opendir('.')) {
        while (
    false !== ($file readdir($handle))) {
            if (
    $file != "." && $file != ".." && !in_array(pathinfo($filePATHINFO_EXTENSION), $aHideExt)) {
                echo 
    "$file<br />";
            }
        }
        
    closedir($handle);

    Won't work in PHP4, to use pathinfo you'd need to assign it to an array and retrieve the 'extension' index out of it.

    Look into wrapping this in a function though. As a function you'll be able to get it to recurse directories and perform a tree listing.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for the reply Fou-Lu,

    I don't really understand what you said

    I will however see what I can do with the code you've provided and if (or when) I get totally lost I'll post back.

    I am using php 5 though I know that much

    TT


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •