CodeIgniter Forums
Upload Model issues. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Upload Model issues. (/showthread.php?tid=1342)



Upload Model issues. - miiikkeyyyy - 03-01-2015

I am creating an upload script for my signed in users.

Libraries included: form, upload and image_lib.

From the controller I want to call upon the add image function, from the user model.
From the user model I want it to attempt to upload the file using the upload model.
And once the upload is complete I want the user model to create the thumbnails and add to database.

I get a dreaded The upload path does not appear to be valid. every single time.
I know the path works as I wrote echo $config['upload_path'] and copied the result in my browser and it took me to the directory.
Could someone shed some light on why I always get the error?

In my controller/profile.php I have:
PHP Code:
if($this->input->post())
        {                        
            if(!
$this->user_model->add_image())
            {
                
$data['errors'] = $this->upload->display_errors();
            }


In my models/user_model.php I have:
PHP Code:
function add_image()
    {
        
$config['upload_path'] = './public/images/';
        
$config['allowed_types'] = 'gif|jpg|png';
        
$config['max_size']    = '100';
        
$config['max_width' '1024';
        
$config['max_height' '768';

        if(
$this->upload_model->upload($config))
        {
            
$data $this->upload->data();
            
            
$config = array(
             
   'user_id' => $this->session->userdata('user_id'),
             
   'file_name' => $data['file_name']
            );
            
$this->db->insert('user_images'$config);
            
            
$this->load->library('image_lib');                
            
createThumbnail($data"small"6060); 
            
createThumbnail($data"medium"200200);
            return 
true;
        }
        else
        {
            return 
false;    
        }
        
    } 

In my models/upload_model.php I have:
PHP Code:
function upload($config)
 
   {
 
       if(!file_exists($config['upload_path']))
        {
         
   mkdir($config['upload_path'], 0777true);
        }
        
        if(
$this->upload->do_upload())
        {
            return 
true;
        }
        else
        {
            return 
false;
        }    
    } 



RE: Upload Model issues. - mwhitney - 03-05-2015

In models/upload_model.php, before:

PHP Code:
if ($this->upload->do_upload()) 

you probably need to add:
PHP Code:
$this->load->library('upload'$config); 

Otherwise, wherever you're loading the upload library is where you're getting the $config values, so your upload path is probably set to a default value rather than the $config value you're passing to your model.