directory - php "is_dir" file listings for Intranet site -
i'm creating test file files located in intranet folder , put icon image next file listed according extension. reason, code not pulling things correctly.
here's screen shot of windows explorer view of files in directory.
and here code:
<?php $dir="file:///.....to_my_directory"; // directory files stored if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) != false) { if (is_dir($filename)) { $img = 'folder_img.jpg'; } else { $filestuff = pathinfo($filename); $file_ext = isset($filestuff['extension']) ? $filestuff['extension'] : null; switch($file_ext) { case 'pdf': $img = 'pdf_img.jpg'; break; case 'doc' || 'docx' || 'docm' || 'dotm' || 'dotx': $img = 'word_img.jpg'; break; case 'xls' || 'xlsm' || 'xltx' || 'xlam' || 'xlsx' || 'xlm' || 'xlt' || 'xlsb': $img = 'excel_img.jpg'; break; case 'txt': $img = 'txt_file_img.jpg'; break; case null: $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); } ?>
and how looks when run it:
the problem extensions not listed pulling 'microsoft word' icon.
the 'access database' file extension '.mdb' pulling word icon, extension '.mdb_hcu' pulling word icon.
how make blank file option (see switch case answer null)
also, how organize folders listed first , in alphabetical order?
is there plugin allows me achieve easier?
problem can't list case values this:
case 'doc' || 'docx' || 'docm' || 'dotm' || 'dotx':
that evaluated 1 statement evaluate true. extension compare result , unless extension null
, case true.
you need list out each case option so:
case 'doc': //if case 'docx': //any case 'docm': //of case 'dotm': //these case 'dotx': //are true //this run //set image break; //up
if of cases true (equal extension), code inside case run until break
hit.
Comments
Post a Comment