CI框架之图片上传

来源:互联网 发布:只有我知3小时14分超清 编辑:程序博客网 时间:2024/05/29 02:38

如图所示

        控制器

class Welcome extends CI_Controller {   public function index()   {      if($_POST)      {         $config['upload_path'] = './public/uploads/';         $config['allowed_types'] = 'gif|jpg|png';         $config['max_size'] = '0';         $config['max_width'] = '0';         $config['max_height'] = '0';         $config['encrypt_name']=true;   //文件重命名         $this->load->library('upload', $config);         $this->upload->initialize($config);         $result=$this->upload->do_upload('s_file');//执行操作,s_file是你存放图片路径的字段         $a=$this->upload->data();   //打印你图片的信息              $dat['s_file']='./public/uploads/'.$a['file_name'];            //接收表单其他值           $s_desc=$this->input->post('s_desc');          $dat['s_desc']=$s_desc;          $a=$this->db->insert('day01',$dat);         if($a)         {            echo "<script>alert('入库成功');location.href='".site_url('Welcome/show')."'</script>";         }   }      else      {        $this->load->view('form.html');      }   }   public function show()   {       $data['list']=$this->db->get("day01")->result_array();  //row_array  查一条      $this->load->view('index.html',$data);   }}

视图层


<center> <table>        <tr>            <th>id号</th>            <th>描述</th>            <th>图片</th>        </tr>         <?php foreach($list as $value) { ?>         <tr>             <td><?php echo $value['s_id']?></td>             <td><?php echo $value['s_desc']?></td>             <td><img src="<?php echo base_url().$value['s_file']?>" width="100" height="50"></td>         </tr>     <?php   }?>    </table></center>








1 0
原创粉丝点击