冯 海

一个程序新人菜鸟的日记,希望大家多多关照。QQ:32316131

Discuz!系列教程:添加自定义附件图标

Discuz!x3.2在使用是,对于未知的文件类型,直接显示问号图标,为了让站长自己的文件类型能显示正确图标,特分享以下教材。适用版本:Discuz!x2.5-x3.2

工具/原料

 
  • Discuz!x3.2 程序一套

方法/步骤

 
  1.  

    将apk图  上传到目录:static\image\filetype 保存为apk.png

    Discuz!系列教程:[5]添加自定义附件图标
  2.  

    打开文件,路径为:\source\function\function_attachment.php

  3.  

    搜索:

    function attachtype($type, $returnval = 'html') {

     

            static $attachicons = array(

                            1 => 'unknown.gif',

                            2 => 'binary.gif',

                            3 => 'zip.gif',

                            4 => 'rar.gif',

                            5 => 'msoffice.gif',

                            6 => 'text.gif',

                            7 => 'html.gif',

                            8 => 'real.gif',

                            9 => 'av.gif',

                            10 => 'flash.gif',

                            11 => 'image.gif',

                            12 => 'pdf.gif',

                            13 => 'torrent.gif'

                    );

     

    修改为:

    function attachtype($type, $returnval = 'html') {

     

            static $attachicons = array(

                            1 => 'unknown.gif',

                            2 => 'binary.gif',

                            3 => 'zip.gif',

                            4 => 'rar.gif',

                            5 => 'msoffice.gif',

                            6 => 'text.gif',

                            7 => 'html.gif',

                            8 => 'real.gif',

                            9 => 'av.gif',

                            10 => 'flash.gif',

                            11 => 'image.gif',

                            12 => 'pdf.gif',

                            13 => 'apk.png',

                            14 => 'torrent.gif'

                    );

     

  4.  

    搜索:

    if(is_numeric($type)) {

                    $typeid = $type;

            } else {

                    if(preg_match("/bittorrent|^torrent\t/", $type)) {

                            $typeid = 13;

                    } elseif(preg_match("/pdf|^pdf\t/", $type)) {

                            $typeid = 12;

                    } elseif(preg_match("/image|^(jpg|gif|png|bmp)\t/", $type)) {

                            $typeid = 11;

                    } elseif(preg_match("/flash|^(swf|fla|flv|swi)\t/", $type)) {

                            $typeid = 10;

                    } elseif(preg_match("/audio|video|^(wav|mid|mp3|m3u|wma|asf|asx|vqf|mpg|mpeg|avi|wmv)\t/", $type)) {

                            $typeid = 9;

                    } elseif(preg_match("/real|^(ra|rm|rv)\t/", $type)) {

                            $typeid = 8;

                    } elseif(preg_match("/htm|^(php|js|pl|cgi|asp)\t/", $type)) {

                            $typeid = 7;

                    } elseif(preg_match("/text|^(txt|rtf|wri|chm)\t/", $type)) {

                            $typeid = 6;

                    } elseif(preg_match("/word|powerpoint|^(doc|ppt)\t/", $type)) {

                            $typeid = 5;

                    } elseif(preg_match("/^rar\t/", $type)) {

                            $typeid = 4;

                    } elseif(preg_match("/compressed|^(zip|arj|arc|cab|lzh|lha|tar|gz)\t/", $type)) {

                            $typeid = 3;

                    } elseif(preg_match("/octet-stream|^(exe|com|bat|dll)\t/", $type)) {

                            $typeid = 2;

                    } elseif($type) {

                            $typeid = 1;

                    } else {

                            $typeid = 0;

                    }

            }

    修改为:

    if(is_numeric($type)) {

                    $typeid = $type;

            } else {

                    if(preg_match("/bittorrent|^torrent\t/", $type)) {

                            $typeid = 14;

                    } elseif(preg_match("/apk|^apk\t/", $type)) {

                            $typeid = 13;

                    } elseif(preg_match("/pdf|^pdf\t/", $type)) {

                            $typeid = 12;

                    } elseif(preg_match("/image|^(jpg|gif|png|bmp)\t/", $type)) {

                            $typeid = 11;

                    } elseif(preg_match("/flash|^(swf|fla|flv|swi)\t/", $type)) {

                            $typeid = 10;

                    } elseif(preg_match("/audio|video|^(wav|mid|mp3|m3u|wma|asf|asx|vqf|mpg|mpeg|avi|wmv)\t/", $type)) {

                            $typeid = 9;

                    } elseif(preg_match("/real|^(ra|rm|rv)\t/", $type)) {

                            $typeid = 8;

                    } elseif(preg_match("/htm|^(php|js|pl|cgi|asp)\t/", $type)) {

                            $typeid = 7;

                    } elseif(preg_match("/text|^(txt|rtf|wri|chm)\t/", $type)) {

                            $typeid = 6;

                    } elseif(preg_match("/word|powerpoint|^(doc|ppt)\t/", $type)) {

                            $typeid = 5;

                    } elseif(preg_match("/^rar\t/", $type)) {

                            $typeid = 4;

                    } elseif(preg_match("/compressed|^(zip|arj|arc|cab|lzh|lha|tar|gz)\t/", $type)) {

                            $typeid = 3;

                    } elseif(preg_match("/octet-stream|^(exe|com|bat|dll)\t/", $type)) {

                            $typeid = 2;

                    } elseif($type) {

                            $typeid = 1;

                    } else {

                            $typeid = 0;

                    }

            }

     

  5. 5

    修改完成,覆盖同门文件,登陆后台,更新缓存,上传文件测试哦。

    效果如下

     

    Discuz!系列教程:[5]添加自定义附件图标
posted @ 2016-09-11 09:35  秋天来了哟  阅读(294)  评论(0)    收藏  举报
认识就是缘份,愿天下人都快乐!
QQ: 32316131
Email: 32316131@qq.com