Lalit
Lalit

Reputation: 101

The upload path does not appear to be valid”. Codeigniter file upload

        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'doc|docx';
        $config['max_size'] = '400';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

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

    if ( ! $this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());

        $this->load->view('upload_form', $error);
    }
    else
    {
        $data = array('upload_data' => $this->upload->data());

  $this->referral_model->postCVReferralInfo($m_id, $emp_id , $job_id, $name, $age , $gender,$country_id, $mobile, $email, $summary, $workExp, $education, $qualification, $offer, $sb_id);
    header('location:'.$this->config->base_url().'index.php/member/referSuccess');

    exit;



    } ` 

If I try to upload the doc file then I'm getting this error "The upload path does not appear to be valid". I replaced the path to absolute Path then also I am getting this error. please suggest me how I can resolve the issue.`

Upvotes: 9

Views: 41222

Answers (8)

Nithesh
Nithesh

Reputation: 204

Create a folder with uplaods in the root directory and use following code in controller

$config['upload_path'] =  'uploads';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 2000;
$config['max_width'] = 1500;
$config['max_height'] = 1500;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('profile_pic')) 
{
   $error = array('error' => $this->upload->display_errors());
}else{
   $data = array('image_metadata' => $this->upload->data());
} 

Upvotes: 0

Rosoldier
Rosoldier

Reputation: 1

**look after this line: ** $this->load->library('upload', $config);

    **Then add this short code**

$this->upload->initialize($config);

UPLOAD SUCCESSFULL

Upvotes: -2

Driss Baidou
Driss Baidou

Reputation: 305

i was facing the same error, here's my code.

        // Upload Image
        $config['upload_path'] = './uploads';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '7048';
        $config['max_width'] = '7000';
        $config['max_height'] = '7000';

        // Create folder (Uploads) if not exists
        if (!is_dir($config['upload_path'])) {
            mkdir($config['upload_path']);
        }

        // Load library Upload
        $this->load->library('upload', $config);

        // Initialize the Upload library with curront $config
        $this->upload->initialize($config);

        $this->upload->do_upload();
        if ($this->upload->do_upload()) {
            $data = array('upload_data' => $this->upload->data());
            $page_image = $_FILES['userfile']['name'];
        } else {
            $errors = array('error' => $this->upload->display_errors());
            $page_image = 'noimage.jpg';
        }

        $this->page_model->create_page($page_image);

        // Set message
        $this->session->set_flashdata('page_created', 'Your page has been created');

        redirect('admin/pages/create');

try to past

        $this->upload->initialize($config);

just after loading the library Upload

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

Upvotes: 0

Nit
Nit

Reputation: 239

better use:

$config["upload_path"] = $_SERVER['DOCUMENT_ROOT']."/your/desired/location/";

And initialize your config by:

$this->upload->initialize($config);

Upvotes: 1

Uchenna Nnodim
Uchenna Nnodim

Reputation: 484

never use base_url() in $CONFIG['UPLOAD_PATH'],

Take note of the dot before the backslash preceding your upload folder. Hence your upload path should look like this

 $CONFIG['UPLOAD_PATH'] = './assets/uploads/

Upvotes: 2

Uday Laddu
Uday Laddu

Reputation: 81

Same problem...solved by

$this->upload->initialize($config);

And better not to use....BASE_URL in $CONFIG['UPLOAD_PATH']

Upvotes: 7

Priya Jayapal
Priya Jayapal

Reputation: 261

The problem usually occurs when a call to $this->load->library('upload', $config), may be it does not load the configuration settings, so try adding the following statement after loading the upload library.

$this->upload->initialize($config);

Upvotes: 15

Ahmed Bermawy
Ahmed Bermawy

Reputation: 2530

change your code to this $config['upload_path'] = 'uploads';

Upvotes: 0

Related Questions