0

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

2 Answers 2

1

Thanks everyone for the reply

I already solved it

I just initialize again the upload using

$this->upload->initialize();
Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

so what possible solution can I do? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.