CI(4) 文件上传
扫描二维码
随时随地手机看文章
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()函数
public function __construct() { parent::__construct(); $this->load->helper(array('form','url')); }