微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 使用codeigniter上传时“没有选择要上传的文件”

我试图上传图像,但它总是给我“你没有选择要上传文件.”

我的控制器

function add()
{

        $thedate=date('Y/n/j h:i:s');
        $replace = array(":"," ","/");
        $newname=str_ireplace($replace,"-",$thedate);

        $config['upload_path'] = './upload/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['file_name']=$newname;
        $config['max_size'] = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

        $this->load->library('upload',$config);
        //$this->upload->initialize($config);
        $this->load->library('form_validation');

        $this->form_validation->set_rules('title','title','trim|required');
        $this->form_validation->set_rules('description','Description','trim|required');
        $image1=$this->input->post('image');


     if ($this->form_validation->run()==FALSE){

            $this->addview();   

            return false;

        }


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

        $error = array('error' => $this->upload->display_errors());
        $this->load->view('upload_error',$error);


         }

       else {
        $mage=$this->upload->do_upload($image1);

            $data =array(
            'title'=>$this->input->post('title'),'descrip'=>$this->input->post('description'),'image' => $mage['file_name']

    );  


            $this->load->model('member_functions');

            $q=$this->member_functions->insert($data);
    }}

设置了所有文件要求和文件权限,但我仍然得到了那个错误.有人可以告诉我,我做错了什么

参数$this-> upload-> do_upload()函数应该是表单字段的名称. (如果你在没有参数的情况下调用它,则会使用userfile).在你的情况下,它似乎应该是’形象’.代替:
$image1=$this->input->post('image');

它应该是:

$image1='image';

原文地址:https://www.jb51.cc/php/135752.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐