# 新增文件类型图标的方法
pptx文件不在论坛默认的文件类型范围之内,因此上传的pptx文件图标显示为未知,这对于我这种强迫症患者怎么可以忍受,解决方案如下
## 图片文件的下载
网上十分容易下载,修改成32x32大小,并且命名为“pptx.jpg”,存放在static/image/filetype目录下即可,接下来需要在源代码中做些许修改
## 增添新的文件类型
相关代码文件是source/function/function_attachment.php
```php
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'
);
```
我们需要在末尾增加一个新的图片文件,注意逗号!
```php
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',
14 => 'pptx.jpg'
);
```
此外,需要在接下来的代码上设置文件类型关联,修改前的代码如下
```php
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;
```
修改之后则变成
```php
if(is_numeric($type)) {
$typeid = $type;
} else {
if(preg_match("/ppt|^(pptx|ppt)\t/", $type)) {
$typeid = 14;
} elseif(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;
```
如此以来,我们就完成了新的文件类型图片的添加,在论坛上可以做尝试了,前后对比结果如下
修改前:
修改后:
显然,问题得到成功解决!