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 Coder
    Join Date
    Sep 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how do I restrict file types that are shown?

    Hello,

    I have this code to make a simple photogallery:
    PHP Code:
    <?
    echo "<HTML><BODY Bgcolor=black><CENTER>";
    chdir('.');
    $handle=opendir('.');
    readdir($handle);
    readdir($handle);
    echo 
    "<BR>";
    while ((
    $file readdir($handle))!==false){
    $size=(filesize($file)/100);
    echo 
    "<TABLE BORDER=1 BORDERCOLOR=BLUE><TR bgcolor=dddddd><TD><A HREF=$file><img src=$file width=200 height=160></A></TD><TD width=200 height=75>Name: $file <BR> Size: $size Kb</TR></TABLE>";
    }
    echo 
    "<BR>";
    ?>
    I would like to know how to make so it only reads .jpg, .gif, .png, and .bmp files.

    Currently it tries to make a thumbnail of every file in the directory


    Any help would be awesome Thanks!

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,051
    Thanks
    10
    Thanked 94 Times in 92 Posts
    not tried this but its worth a shot , getimagesize should return false if the file is not a valid image ..

    PHP Code:
    <?
    while (($file readdir($handle))!==false){
    if(@
    getimagesize($file)){
    $size=(filesize($file)/100);
    echo 
    "....etc";
    }
    }
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Sep 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    RE

    Hey thanks it worked like a charm!!

    Thank you very much.


  •  

    Posting Permissions

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