简体   繁体   中英

CodeIgniter Multiple Upload to 2 different folder

I am trying to do a multiple file upload where in one input['file'] is for image and another one is for video

here is the controller

public function upload(){
  $data['errorPic'] = $this->validateUpload();  
  $data['errorVid'] = $this->validateUpload2();
}

public function validateUpload(){
    if ( $_FILES AND isset($_FILES['coverImage']['name']) ){
        $config['upload_path'] = 'blogpics/';
        $config['allowed_types'] = 'png|gif|jpg|jpeg';
        $config['max_size'] = '999999';

        $this->load->library("upload",$config);

        if(!$this->upload->do_upload("coverImage")){
            return $this->upload->display_errors();
        }
    }   
}

public function validateUpload2(){
    if ( $_FILES AND isset($_FILES['video']['name'])){
        $config['upload_path'] = 'blogvids/';
        $config['allowed_types'] = 'png|gif|jpg|jpeg';
        $config['max_size'] = '999999';

        $this->load->library("upload",$config);

        if(!$this->upload->do_upload("video")){
            return $this->upload->display_errors();
        }
    }
}

only the first function that is called is working

example: if I put first the validateUpload2() Function on the top of validateUpload() function, the first function on the top is working the second one did not

Thanks everyone for the reply

I already solved it

I just initialize again the upload using

$this->upload->initialize();

The reason it is not working is because files uploaded are temporary until moved. Once move_uploaded_file is executed, the temporary file is no longer accessible. If in the second function you call is_uploaded_file, it will return false.

Look into copying the file you wrote to the first directory to the second folder.

Edit

Looks like you changed your post around. That scenario is different from the previous.

This time, it looks like there are two separate files being uploaded.

Looks like it should work, but im looking into it. I wonder if it has to do with the reinitialization of the upload helper class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM