[精讚] [會員登入]
1602

[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

你可能感興趣的文章

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

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

[PHP] 陣列新增資料及整理 在php陣列加入項目和重新整理陣列的方法

設定Google analytics API #2 -- PHP的程式安裝和撰寫 讓你的網站能夠存取你的Google analytics上面的資料

[Smarty5] 如何在樣版中使用php本身的函式 解決 smarty5版後不能直接叫用 php函式的問題

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

隨機好文

[jQuery] select 元件的取值及給值 html中的元件select,在jquery中要如何使用?

看懂DSUB DVI HDMI USB等各式影音接頭 看懂DSUB DVI HDMI等各式影音接頭

[MAC] 安裝APACHE+PHP OS Darwin OpenIDMac1deAir 15.6.0 Darwin Kernel Version 15.6.

[PHP]解決ksort新增的SORT_NATURAL|SORT_FLAG_CASE方法 php>=5.4中ksort函數多了SORT_NATURAL 和 SORT_FLAG_CASE 旗標,對舊版的PHP中要怎麼辦?

[AS3] 物件加上超連結的方法 物件加上超連結,可讓使用者點擊的方法