[精讚] [會員登入]
1618

[CodeIgniter3] 解決無法上傳特定檔案(.sb2)的問題

上傳時出現The filetype you are attempting to upload is not allowed,要怎麼解決?

分享此文連結 //n.sfs.tw/10096

分享連結 [CodeIgniter3] 解決無法上傳特定檔案(.sb2)的問題@新精讚
(文章歡迎轉載,務必尊重版權註明連結來源)
2019-10-22 09:31:26 最後編修
2016-10-29 20:43:20 By 張○○
 

這近想要讓使用者上傳Scratch2 的檔案類型*.sb2,發現怎麼試都會出現

The filetype you are attempting to upload is not allowed

的錯誤,一開始以為是自己的問題,耗了不少時間。也不知道要怎麼解決?!

後來研究了原始碼和自行測試,找到了解決方法,未來解決未定義類型的檔案,也可以依此方法來解決。

設定上傳允許的類型 加入'sb', 'sb2'

$config['allow_upload_type'] = array('jpg', 'png', 'jpeg','sb2','sb');
$config['allowed_types'] = implode('|', $config['allow_upload_type']);

第2行allowed_types是系統所需要的格式,第1行是為了方便設定自行添加的,在讀入library時用設定檔建構

$upload_config['allowed_types']= $this->config->item('allowed_types');
$upload_config['file_ext_tolower'] = true;
$this->load->library('upload',$upload_config);

修改 config/mimes.php 加入

'sb'=> array('application/x-scratch2','application/octet-stream','application/zip'),
'sb2'=> array('application/x-scratch2','application/octet-stream','application/zip'),

這樣就可以了

 

END

你可能感興趣的文章

[PHP>7.3] switch中的 Did you mean to use "continue 2"? 除錯 這近更新 PHP到7.3版以後,出現這樣的錯:targeting switch is equivalent to "break". Did you mean to use "continue 2"?解決方法

設定Google analytics API #1 -- Google網站上的設定 讓你的網站能夠存取你的Google analytics上面的資料

[PHP] 移除陣列或字串中的重覆元素 移除陣列或字串中的重覆元素

PHP 數字加解密函式 自寫的數字加解密,勉強用

[PHP] CodeIgniter 3+pure+smarty安裝及環境設置1/2 PHP framework CodeIgniter 3+ pure CSS +smarty Template Engine的整合

[CodeIgniter 3] 資料庫的使用方法整理1/2 --Select的使用 [CodeIgniter 3] 資料庫的使用方法整理:Select的使用

隨機好文

談借錢 人借錢時手心向上頭向下,人還錢時手心向下頭向上

UTF-8 BOM (Byte Order Mark) 的問題 在 Michael Kaplan 那看到 Every character has a story #4: U+feff

為什麼要重造輪子? 什麼輪子?造什麼輪子?我為什麼要重造輪子?

維修冰箱 維修冰箱

一個邏輯的錯誤刪了全部檔案的經驗 今天本來想做一件很簡單的事,但卻足足浪費我多一倍的時間,再加上刪掉我全部的檔案,原因只是因為我自己的邏輯錯誤。