...

View Full Version : need help: directory opens but contents wont display properly



bensonang
03-05-2007, 09:03 AM
the code below displays all images located in the current directory.
my problem is, if i specify a directory name to $filedir, example $filedir = "pictures"; the only thing that would display
are blank boxes with an X (i think it means unloaded picture).

anyone had this kind of problem before? need suggestions please. thanks.

<?php

// Set $filedir to '.' if in current directory
$filedir = ".";

$handle = opendir($filedir);
echo $filedir;
while ($filename = readdir($handle)) {

// One way to get the file extension
$ext = strtolower(substr(strrchr($filename, '.'),1));

if ($ext == 'jpeg' || $ext == 'jpg') {
echo "<img src='$filename'>";
}
}
closedir($handle);

?>

i've tried using $filedir = "./pictures/"; and $filedir = "pictures/"; neither of the two works.

note: that pictures folder is located in the same directory as the php file.

aku
03-05-2007, 10:19 AM
<?php

$file_dir = './' ;
$handle = opendir( $file_dir ) ;
while( false !== ( $file_name = readdir( $handle ) ) ) {
$file_ext = strtolower( pathinfo( $file_name, PATHINFO_EXTENSION ) ) ;
if( $file_ext == 'jpeg' || $file_ext == 'jpg' )
print "<img src=\"$file_name\" />" ;
}
closedir( $handle ) ;

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum