Search code examples
phpcodeigniter

Uploading files in codeigniter


A Problem was encountered while attempting to move the uploaded file to the final destination

Unable to upload the file in codeigniter using their upload class, upload directory is also exist, below is a code

$config = array(
                'upload_path' => './upload_dir/users_docs/',
                'allowed_types' => 'gif|png|jpeg',
                'max_size' => 0,
                'max_width' => 0,
                'max_height' => 0,
                'file_name' => $this->currTime,
        );
        $this->load->library('upload', $config);
        if (!empty($_FILES['company_logo']['name']) && !$this->upload->do_upload('company_logo')) {
            $error = array('error' => $this->upload->display_errors());
            $this->session->set_flashdata('error_message', $error['error']);
            redirect('home');
        }
        $data = array('upload_data' => $this->upload->data());

Solution

  • There was an issue in the 'file_name' => $this->currTime, the format of time was not correct, Apostrophe where coming in the filename var, I just changed it to something else, now it's working, Thank you