CI里文件上传

 //表单

<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');
        }
    }


}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值