//載入所需類庫
$this->load->library('upload');
//配置上傳參數
$upload_config = array(
'upload_path' => '',
'allowed_types' => 'jpg|png|gif',
'max_size' => '500',
'max_width' => '1024',
'max_height' => '768',
);
$this->upload->initialize($upload_config);
//循環處理上傳文件
foreach ($_FILES as $key => $value) {
if (!empty($key['name'])) {
if ($this->upload->do_upload($key)) {
//上傳成功
print_r($this->upload->data());
} else {
//上傳失敗
echo $this->upload->display_errors();
}
}
}
註:
//設定
// 允許 Word 檔上傳
$config['allowed_types'] = 'doc|docx';
// 允許圖檔上傳
$config['allowed_types'] = 'gif|png|jpg|jpeg|jpe';
// 不限制上傳檔案類型
$config['allowed_types'] = '*';
//單檔上傳程式
if ($this->upload->do_upload('file1')) { //<input name="file1" type="file" id="file1">
//上傳成功
print_r($this->upload->data());
} else {
//上傳失敗
echo $this->upload->display_errors();
}
沒有留言:
張貼留言