Welcome Guest, Not a member yet? Register   Sign In
[solved]Upload not working
#1

[eluser]Clooner[/eluser]
I use the upload library but somehow it says the directory is not correct. I checked this using the file helper and writing a file to that directory. Writing the file works so, I must be overlooking something in the upload library. Anyone ideas?

Code:
function images($id)
    {
        // get the correct data
        if ($this->prep_for_edit($id))
        {
            // check if path exists! or else create it!
            if (!is_dir(img_path().$id))
                mkdir(img_path().$id,0777);
        
        
            // TODO: remove, test if I can write data!
            $fdata = 'Some file data';
            $this->load->helper('file');
            if ( ! write_file(img_path().$id.'/'.date('lHis').'.txt', $fdata))
                $this->data['debug']['writable'] = 'Unable to write the file';
            else
                $this->data['debug']['writable'] = 'File written!';

            // overwrite the default form
            $this->data['form']['submit'] = "Foto uploaden";
            $this->data['form']['type'] = "multipart";

            $config['upload_path']     = img_path().$id;
            $config['allowed_types']   = 'jpg|png';
            $config['max_size']           = '2048';
            $config['max_width']       = '1600';
            $config['max_height']      = '1200';
            $config['overwrite']       = 'TRUE';
            $this->load->library('upload', $config);

            // TODO: remove next line
            $this->data['debug']['config']=$config;

             if (!empty($_FILES))
            {
                // TODO: remove next line
                $this->data['debug']['files']=$_FILES;
                
                if ($this->upload->do_upload('produce_image'))                
                {
                    // TODO: remove next line
                    $this->data['debug']['uploadsuccessdata']=$this->upload->data();
                    $this->data['messages']['information'][]="Foto succesvol geupload";
                } else
                {
                    // TODO: remove next line
                    $this->data['debug']['uploadfaileddata']=$this->upload->data();
                    $this->data['messages']['error']=array_merge($this->data['messages']['error'],$this->upload->error_array());
                }
            }
            $this->data['section']['content'][] = 'form_editor';
            // TODO: remove next line
            $this->data['section']['content'][] = 'debug_data';
        }
    }
#2

[eluser]Jondolar[/eluser]
I would echo out the return value from the image_path() function to make sure it has what you expect.
#3

[eluser]Clooner[/eluser]
[quote author="Jondolar" date="1249796206"]I would echo out the return value from the image_path() function to make sure it has what you expect.[/quote] I do echo the upload path and that is correct. I even use the img_path var and the file helper to write a file in that directory. The directory is chmod 777 and writable using the file helper. How come I cannot access it using the upload library?
#4

[eluser]Clooner[/eluser]
The weird thing is that when I use the native php function it works flawless
Code:
if(move_uploaded_file($_FILES['userfile']['tmp_name'],img_path().$id.'/test.jpg'))//$chmod o+rw galleries
Seems to be a bug or somehow me abusing the upload library.
#5

[eluser]Clooner[/eluser]
Seems that I never initiated the config file... (Maybe this could also be a error of the upload library)

I used a MY_upload library to extend the error handling a bit. I forgot to correctly pass through the $config array....




Theme © iAndrew 2016 - Forum software by © MyBB