//设置文件上传属性$webroot = $_SERVER['DOCUMENT_ROOT'];$time = time();$year = date('Y', $time);$month = date('m', $time);$day = date('d', $time);$subpath = "/goods/coverimage/{$year}/{$month}/{$day}/";$path = $webroot . '/uploads' . $subpath;if(!file_exists($path)){ mkdir($path, 0777, true);}$config['upload_path'] = $path;$config['allowed_types'] = 'jpg|gif|png';$config['file_name'] = date('YmdHis', $time) . mt_rand(100, 999);$this->load->library('upload', $config);if($this->upload->do_upload('coverimage')){ $file = $this->upload->data(); $data['image0'] = $subpath . $file['orig_name']; if($this->goods_model->add_goods($data)) { $this->success(base_url() . 'admin.php?c=goods', '添加商品成功', 2); }}else //图片上传失败{ $msg = array(); $msg['file_error'] = strip_tags($this->upload->display_errors()); $this->view('goods/modify', $msg);}
$this->upload->do_upload('coverimage')$this->upload->data()$this->upload->display_errors()