bensonang
03-05-2007, 08: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.
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.