[精讚] [會員登入]
1597

[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+ci4] codeignitor4 Cache 及 Session 使用 memcached php 的framework codeignitor4 中的cache和session使用memcached

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

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

PHP程式經驗 #1 -- 靜態的物件比動態物件快 驗證 1. 使用動態物件函式 > 使用靜態物件函式。 2. 使用有宣告的靜態物件函式 > 使用動態無宣告的靜

[PHP] 檢查IP是否在某個網段內 mtachcidr 要檢查IP是否在某個網段內,要寫幾行?10行?5行? 不用,只要2行。以下是我寫的 code /** * matchCI

[PHP] 隨機產生一個顏色字串 讓PHP 隨機產生一個顏色字串

隨機好文

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

[CodeIgniter3] 解決無法上傳特定檔案(.sb2)的問題 上傳時出現The filetype you are attempting to upload is not allowed,要怎麼解決?

世紀帝國征服者新版本--被遺忘的帝國 世紀帝國征服者新版本--被遺忘的帝國 世紀二代的征服者是精典遊戲中的精典,aofe更好玩...

[PHP] 檢查檔案是否是圖檔 使用getimagesize函數檢查檔案是否是圖檔

[大型機台] 熱血高校躲避球 多少少年時光歲月耗在這個遊戲上,二十幾年前的那個時光,唯一想做的事就是把吃飯錢省下來拿去打一場五塊錢的電動,就算是沒錢也