Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
586 views
in Technique[技术] by (71.8m points)

php - "did not select a file to upload" when uploading using codeigniter

im trying to upload an image but it always give me "You did not select a file to upload."

My controller

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

all the file requirements and the file permissions are set but i still get the that eror. can someone please tell me what am i doing wrong

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Parameter to $this->upload->do_upload() function should be the name of the form field. (If you call it without parameters userfile would be used). It seems in your case it should be 'image'. Instead of:

$image1=$this->input->post('image');

it should be:

$image1='image';

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...