...

View Full Version : how do I restrict file types that are shown?



MrTickles
02-15-2003, 02:05 PM
Hello,

I have this code to make a simple photogallery:


<?
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!

firepages
02-15-2003, 04:04 PM
not tried this but its worth a shot , getimagesize should return false if the file is not a valid image ..



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

MrTickles
02-15-2003, 07:04 PM
Hey thanks it worked like a charm!!

Thank you very much.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum