【问题标题】:How to upload images using codeigniter?如何使用codeigniter上传图片?
【发布时间】:2016-10-05 09:42:23
【问题描述】:

我的控制器功能是

 <?php 
    class Image extends CI_Controller
    {
    public function index()
    {
        $this->load->view('image');
    }
    public function upload()
    {
    $config['upload_path'] = './images/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size']    = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';
    $this->load->library('upload', $config);
    $this->upload->initialize($config);
    if (!$this->upload->do_upload())
    {
    $error = array('error' =>$this->upload->display_errors());
    $this->load->view('image',$error);
     }
    else
    {
    $data = array('upload_data' => $this->upload->data());
     }
     }
     }
     ?>

我的视图函数是

  <?php echo $error; ?>
  <?php
  echo form_open_multipart('image/upload');  ?>
  <input name="myFile" size="40" type="file" />
  <input type="submit" value="Upload" />
  </form>

【问题讨论】:

  • 注意:在codeigniter中你不需要关闭你的控制器?&gt;

标签: php codeigniter file-upload


【解决方案1】:

这是错误的。

if (!$this->upload->do_upload()) 

如下使用。在do_upload()方法中使用字段名

if (!$this->upload->do_upload('myFile')) 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-31
    • 2015-01-31
    • 2015-11-08
    • 1970-01-01
    • 2013-08-23
    • 2011-06-08
    相关资源
    最近更新 更多