duan20081202 2014-10-26 23:42
浏览 60

codeigniter $ this-> upload-> do_upload()= false

I'm trying to upload a file. I select a file and then I submit it but result of $this->upload->do_upload() is always false.

Here is my form;

<?php echo form_open_multipart(base_url('files/fileUpload')); ?>
        <input type="file" name="userfile" class="btn btn-default" size="20"/>
        <input type="submit" value="upload" />

</form>

and here is my controller;

public function __construct() {    
      parent::__construct();
      $this->load->helper(array('form', 'url'));
}

public function fileUpload(){
        $this->load->library('upload');
        $data = array('upload_data' => $this->upload->data());
        var_dump($this->upload->do_upload());die;
}

Do I miss something ? What do I need to do ?

Thank you..

  • 写回答

1条回答 默认 最新

  • duanba7498 2014-10-27 05:17
    关注

    There is problem with code in controller fileUpload function

    Try with below code

    public function fileUpload(){
            $config['upload_path'] = './assets/uploads/';
            $config['allowed_types'] = 'gif|jpg|png';
            $this->load->library('upload',$config);
            $data = array('upload_data' => $this->upload->data());
            var_dump($this->upload->do_upload());die;   
        }
    

    Here you need to define file upload path and file allow types.

    Hope this will help you.

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100