您必須對未知類型的文件使用默認圖標。
您可能會顯示在表例如文件
HTML
<tr>
<td class="fm fm_file">
<a target="_blank" href="./download.php?f=something">yourfile.jpg</a>
</td>
</tr>
,做這個(較大庫的片段)我的代碼片段
PHP
if ($handle = opendir($directory)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
if (!is_dir($directory . DIRECTORY_SEPARATOR . $entry)) {
$md = rand(0, 9) . substr(md5('download' . $entry), 1, 10) . rand(1000, 9999);
$dlink = '<a target="_blank" href="./download.php?f=' . $entry . '&c=' . $md . '" >' . $entry . '</a>';
$editlink='';
$a=explode('.', $entry);
if(in_array(strtolower(array_pop($a)),array('ini','txt','xml','bin','sql')))
$editlink='<a href="filemanager-edit?dir=' . $subdir.'&f=' . $entry . '&c=' . $md . '" >' . $ledit . '</a>';
$filelist.='<tr>' . '<td class="fm fm_file">' . $dlink . '</td>' . '<td class="edit">'.$editlink.'</td>' . '<td class="delete"><a href="filemanager?action=delete&dir=' . $subdir.'&f=' . $entry . '&c=' . $md . '" >' . $ldelete . '</a></td>' . '</tr>';
} else
$filelist.='<tr>' . '<td class="fm ft_folder"><a href="filemanager?action=view&dir=' . $subdir . $entry . '&c=' . md5($entry) . '" >' . $entry . '</a></td>' . '<td class="edit"></td>' . '<td class="edit"><a href="filemanager?action=view&dir=' . $subdir . $entry . '&c=' . md5($entry) . '" >' . $lchoose . '</a></td>' . '</tr>';
}
}
closedir($handle);
}
分配圖標需要用js
的JavaScript
$('.fm_file').each(function(){
var name=$(this).find('a').html().split('.').pop();
$(this).addClass('ft_'+name);
});
sktóty做IKONW¯¯CSS
CSS
.fm_file{
background-image:url(../../images/filemanager/page_white.png);
}
.ft_folder{
background-image:url(../../images/filemanager/folder.png);
}
.ft_pdf{
background-image:url(../../images/filemanager/page_white_acrobat.png);
}
.ft_cs{
background-image:url(../../images/filemanager/page_white_csharp.png);
}
.ft_xls{
background-image:url(../../images/filemanager/page_white_excel.png);
}
.ft_php{
background-image:url(../../images/filemanager/page_white_php.png);
}
.ft_dll{
background-image:url(../../images/filemanager/page_white_dll.png);
}
.ft_exe,.ft_msi{
background-image:url(../../images/filemanager/page_white_exe.png);
}
.ft_db,.ft_sql{
background-image:url(../../images/filemanager/page_white_db.png);
}
.ft_png,
.ft_jpg,
.ft_bmp,
.ft_gif{
background-image:url(../../images/filemanager/page_white_picture.png);
}
.ft_txt,
.ft_js,
.ft_ini,
.ft_bat,
.ft_css{
background-image:url(../../images/filemanager/page_white_text.png);
}
.ft_htm,
.ft_xml,
.ft_html{
background-image:url(../../images/filemanager/page_white_code.png);
}
.ft_rar,
.ft_zip{
background-image:url(../../images/filemanager/page_white_compressed.png);
}
結果:
如果有人使用未知類型,則使用該類的圖像fm_file。 你總是可以組成一個圖標集合
有很多擴展來做這樣的事情。這就是爲什麼我寫第三個解決方案是不好的解決方案:/ – Koshi