Php control structures

I want to use one or more string functions, such as explode() or substr() or strrchr(), to determine the extension of each file. I want to account for files that might contain four letter extensions, such as .jpeg, or might contain multiple periods in the filename, or might be in upper or mixed case.
If the file is a JPEG or JPG, i want to display the file using HTML image tags. I wanna use a smaller width attribute value, such as 100, and no height attribute, so that the images are scaled by the browser. I dont want to display directories or any other file types. I am new to this php, so any help would be great. I posted the php below

[php]<?php
$dir = “/etc/php5/”;

// Open a known directory, and proceed to read its contents

$dir = “./”;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "filename: $file : filetype: " . filetype($dir . $file) . “
”;
}
closedir($dh);
}
}
?>[/php]

I had someone tell me the $filename is undefined and not set anywhere in the script. Since i am so new to php, i have no idea what they are talking about. The file i have are candlestick.jpg, rollingpin.jpg, table.jpg and table2.jpg. Any help would be great

[php<?php
$dir = “/etc/php5/”;

// Open a known directory, and proceed to read its contents

$dir = “./”;

if (is_dir($dir)) {
$ext = substr($filename, strrpos($filename, ‘.’) + 1);

   if ($dh = opendir($dir)) {
	   
    while (($file = readdir($dh)) !== false) {
        echo "filename: $file : filetype: " . filetype($dir . $file) . "<br/>";
		
    }
    closedir($dh);
}

}][/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service