[精讚] [會員登入]
1582

[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

你可能感興趣的文章

[Codeingitor4] 使用recaptcha v3前後端認證 為了防止機器人說惡意攻擊,我們引入了 recaptcha,此篇結合 php 框架codeignitor4作前後端認證。

[PHP+ci4] codeignitor4+ smarty5 這篇整合 php 的framework codeignitor4 + smarty5。

[PHP] 台灣身分證號及檢查程式 台灣身分證號及PHP檢查程式

使用Yahoo OAuth2 1/2 使用Yahoo OAuth2來認證我的網站

[PHP] 2個程式的觀念 整理2個PHP的程式觀念,參考參考。

[CodeIgniter 3] 取得controller和method的方法 CodeIgniter 3 取得controller和method的方法

隨機好文

PHP for sphinx 函式庫安裝 PECL/sphinx PHP>= 5.2.2 已經能原生支援 sphinx,可是預設的沒有裝,我們得自己裝才能用

TFTP Server 安裝及使用 讓設備的網路設定檔或是韌體經由TFTP拷備出來,操作的方法

APACHE的記錄檔格式 LogFormat 語法 在APACHE中有定義一些記錄的語法模版 在 /etc/httpd/conf/httpd.conf 中: LogForm

正則表達式:Email名稱防止連續輸入點(.)及下底線(_) Email的名稱中要允許特殊符號,但又不允許連續出現的正則表達式

兩次使用InnoDB的慘痛經驗 Mysql 的Innodb引擎雖然好用,但是我得說說我兩次的慘痛經驗,這讓我考慮以後可能不會再使用innodb了