Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter upload image - The upload path does not appear to be valid

I am having issues uploading an image using the codeigniter upload library, I keep getting the error,

The upload path does not appear to be valid.

The file path I am trying to upload too is as follows,

$config['upload_path'] = './media/images/site';

and when I dot the following,

die(var_dump(is_dir($config['upload_path'])));

I get the following returned,

bool(true)

The folder is also writable (777), so I am not sure where I am going wrong, below is my upload code,

$config['upload_path'] = './media/images/site';
        //die(realpath($config['upload_path']));
        //die(var_dump(is_dir($config['upload_path'])));  
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['max_size'] = '1500';
        $config['max_width']  = '390';
        $config['max_height']  = '269';

        $this->load->library('upload',$config);
        if ( ! $this->upload->do_upload() && $_FILES['userfile']['error'] != 4)
        {
            $data['error'] = $this->upload->display_errors();
            $this->template->build('/admin/pages/about_us', $data);
        }
        else
        {
            $image = $this->upload->data();
            if(empty($image['file_name'])) {
                $image['file_name'] = $this->formbuilder->defaults['page_image'];
            }
            $page = array(
                //'page_title' => $this->input->post('page_title'),
                //'page_slug' => $this->input->post('page_slug'),
                'page_content' => $this->input->post('page_content'),
                'page_image' => $image['file_name'],
                'date_created' => date("Y-m-d h:i:s"),
                'created_by' => 1
            );

            if($this->pages_model->insert($this->security->xss_clean($page)))
            {
                redirect('/admin/dashboard');
            }
        }

I cannot see anything glaringly obvious that would stop the file from being uploaded, below is my folder structure of my project

/application
/system 
index.php
.htaccess
/media
    /images
        /site
        /admin
    /css
    /js

If anyone can shed any light on my problem that would be great.

EDIT FOR THE PETULENT DOWNVOTER

What would be causing this problem?

(There is a question, as if it wasn't obvious enough anyway)

like image 973
Udders Avatar asked Feb 23 '23 10:02

Udders


1 Answers

Try to add this line before libary loading line:

 // Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:
    $this->upload->initialize($config);

Don't forget to add this line in template:

<?php echo form_open_multipart('upload/do_upload');?>
like image 194
Oyeme Avatar answered Apr 28 '23 16:04

Oyeme