[精讚] [會員登入]
1617

[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

你可能感興趣的文章

[PHP7] 利用Memcached 儲存 Session Memcached+ PHP7,利用Memcached 儲存 Session。

利用 php 木馬作為駭客攻擊的手法 利用 php 木馬作為駭客攻擊的手法

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

[PHP] 將字串的部分加上遮罩的函式 有些資料會想要隱藏部分的字元,例如身分證號或信用卡號、電話等。我寫了一個函式來完成這個功能。

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

[PHP+ci4] codeignitor4 Cache 及 Session 使用 memcached php 的framework codeignitor4 中的cache和session使用memcached

隨機好文

[jQuery] textarea 的取值和給值 HTML 的 TEXTAREA 標籤若要用 jquery 取值,不能使用 .text() 或 .html() ,使用 .

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

NETCRAFT發現你的網站及作業系統 NETCRAFT可以發現你的網站及作業系統

海棉寶寶超泡杯演奏的sweet victory 章魚哥和海棉寶寶在超泡杯的演奏歌曲

關閉瀏覽器表單的自動完成autocomplete 什麼是自動完成?就是當我們在網頁的輸入文字欄位中打入文字時,瀏覽器會把曾輸入過歷史記錄中找出來讓我們選擇。