//表单
<form action="<?php echo site_url('index/goods_add')?>" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>产品编号:</td>
<td><input type="text" name="c_number"/>设置产品编号,不填将自动创建!</td>
</tr>
<tr>
<td>产品图片:</td>
<td><input type="file" name="file_upload"/></td>
</tr>
<tr>
<td>库存量:</td>
<td><input type="text" name="c_sum"/></td>
</tr>
<tr>
<td>产品价格:</td>
<td><input type="text" name="c_price"/></td>
</tr>
<tr>
<td>产品星级:</td>
<td>
<select name="l_id">
<option value="">请选择</option>
<?php foreach($list1 as $key=>$val){?>
<option value="<?php echo $val['l_id']?>"><?php echo $val['l_name']?></option>
<?php }?>
</select>
</td>
</tr>
<tr>
<td>产品属性:</td>
<td>
<select name="b_id">
<option value="">请选择</option>
<?php foreach($list as $key=>$val){?>
<option value="<?php echo $val['b_id']?>"><?php echo $val['b_name']?></option>
<?php }?>
</select>
</td>
</tr>
<tr>
<td>产品分类:</td>
<td>
<select name="t_id">
<option value="">请选择</option>
<?php foreach($li as $key=>$val){?>
<option value="<?php echo $val['t_id']?>"><?php echo $val['t_type']?></option>
<?php }?>
</select>
</td>
</tr>
<tr>
<td>浏览器标题(title):</td>
<td><input type="text" name="c_title"/></td>
</tr>
<tr>
<td>关键字(keywords):</td>
<td><input type="text" name="c_keywords"/></td>
</tr>
<tr>
<td>描述(description):</td>
<td><input type="text" name="c_description"/></td>
</tr>
<tr>
<td><input type="submit" value="提交"/></td>
<td></td>
</tr>
</table>
</form>
//控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class index extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function __construct(){
parent::__construct();
// $this->load->library('session');
}
public function index1(){
$arr['list1']=$this->db->get('level')->result_array();
//print_r($arr);die;
$arr['list']=$this->db->get('brand')->result_array();
$arr['li']=$this->db->get('type')->result_array();
$this->load->view('face/goods_add.html',$arr);
}
public function goods_add(){
if($this->input->post()){
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 0;
$config['max_width'] = 0;
$config['max_height'] = 0;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
else{
$this->load->view('face/goods_add.html');
}
}
}