|
|
應用場景:JPG格式具有高壓縮率,更適于互聯網傳播,本站僅支持上傳JPG格式的圖片,但部分用戶會直接將 PNG 或 BMP 格式的圖片修改擴展名為 JPG,繞開系統限制。可采用以下方法進行檢測:
1、打開 source/class/discuz/discuz_upload.php 文件,查找:
- $attach['size'] = intval($attach['size']);
復制代碼 在其前方增加:
- $filename = $attach['tmp_name'];
- $file = fopen($filename, "rb");
- $bin = fread($file, 2);
- fclose($file);
- $strinfo = @unpack("C2chars", $bin);
- $typecode = intval($strinfo['chars1'].$strinfo['chars2']);
- if(in_array($typecode, array('7173', '6677', '13780'))) {
- $attach['unsupported_image_format'] = 1;
- }
復制代碼
2、打開 source/class/forum/forum_upload.php 文件,查找:
在其前方增加:
- if($upload->attach['unsupported_image_format'] == '1') {
- return $this->uploadmsg(51);
- }
復制代碼
3、打開 static/js/forum_post.js 文件,查找:
將其替換為:
- '11' : '今日您已無法上傳那么大的附件',
- '51' : '圖像格式不支持,請轉換為 .JPG'
復制代碼
更新緩存,刷新發帖頁面后測試(將一張PNG格式圖片的擴展名修改為JPG,上傳測試,失敗則表示成功)。
|
|