<?php
#### Hmmmm, PHP already has a function that does what
#### your file_type() function does.
#function file_type($file){
# $path_chunks = explode("/", $file);
# $thefile = $path_chunks[count($path_chunks) - 1];
# $dotpos = strrpos($thefile, ".");
# return strtolower(substr($thefile, $dotpos + 1));
#}
function file_type($file) {
return strtolower(pathinfo($file, PATHINFO_EXTENSION));
}
$path = "photos/";
$file_types = array('jpeg', 'jpg', 'ico', 'png', 'gif', 'bmp', 'html');
$p = opendir($path);
while (false !== ($filename = readdir($p))) {
#### Why not put the extension test here?
if ($file != '.' && $file != '..' && array_search($extension, $file_types)) {
#### You could also get the file size now
#$files[] = $filename;
$files[] = array($filename, filesize($path . $filename));
}
}
sort($files);
foreach ($files as $file) {
#### Moved the test outside the loop
#$extension = file_type($file);
#if($file != '.' && $file != '..' && array_search($extension, $file_types)){
$file_count++;
#### As each $file is now an array (with name and size)
#### the $file below needs to specify an index.
#### For the filename the index is 0, it is 1 for the size
echo '<a href="'.$path.$file[0].'"><img src="'.$path.$file[0].'" width=500 height=500/>'.$file[0].'</a> <br/>';
echo 'File size: ', $file[1], ' bytes<br/>';
#}
}
?> |