Can you change case NULL:
to default:
and see if it works please?
default:
means that if it doesn't match any of the "cases" then it will run the default one.
Thanks
:Edited Answer:
You need to change where you set $img = 'folder_img.jpg'
as it sets it to word, then on the next 'while', it's not a dir, so doesn't change, but also doesn't match any case, so stays as it was on the last while
- hope this makes sense!
Let me know if it works for you!
<?php
$dir="."; // Directory where files are stored
if ($dir_list = opendir($dir)) {
while(($filename = readdir($dir_list)) != false) {
$img = 'folder_img.jpg';
if (!is_dir($filename)) {
$filestuff = pathinfo($filename);
$file_ext = isset($filestuff['extension']) ? $filestuff['extension'] : null;
switch($file_ext) {
case 'pdf':
$img = 'pdf_img.jpg';
break;
case 'doc':
case 'docx':
case 'docm':
case 'dotm':
case 'dotx':
$img = 'word_img.jpg';
break;
case 'xls':
case 'xlsm':
case 'xltx':
case 'xlam':
case 'xlsx':
case 'xlm':
case 'xlt':
case 'xlsb':
$img = 'excel_img.jpg';
break;
case 'txt':
$img = 'txt_file_img.jpg';
break;
default:
$img = 'blank_file_img.jpg';
break;
}
}
?>
<p><span><img src='<?php echo $img; ?>' height='23px;'/><a href="<?php echo $filename; ?>"><?php echo $filename;?></a></span></p>
<?php
}
closedir($dir_list);
}
?>