controller:
public?function?uploads() { if($_POST['sub']) { $config['upload_path']?=?'./application/uploads';?//同理?都是以?index.php?為主入口 $config['allowed_types']?=?'jpg|jpeg|png|gif'; $config['max_size']?=?1024;//1M $this->load->library('upload',$config); if(!$this->upload->do_upload())?//上傳失敗 { $error?=?$this->upload->display_errors(); echo?$error; } else?//上傳成功 { $data?=?$this->upload->data(); var_dump($data); } } }
view
注意 必須在controller中加載 helper 才能使用 form_open_multipart()函數(shù)
public?function?__construct() { parent::__construct(); $this->load->helper(array('form','url')); }