CodeIgniter Forums
File upload not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: File upload not working (/showthread.php?tid=18602)



File upload not working - El Forum - 05-12-2009

[eluser]learning_php[/eluser]
Hi,

i had an image upload function working on my localhost but when i put in on the server it gives me a error:

Code:
The upload path does not appear to be valid.
]
controller
Code:
function upload()
    {
        // Image configuration
        $config['upload_path'] = 'uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['overwrite'] = FALSE;
        $config['max_size'] = 4048;
        
        $this->load->library('upload', $config);
        
    
        if(!$this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('upload', $error);
        }
        else
        {
            
        
            $image = $this->upload->data();
            $data['image'] = "uploads/".$image['file_name'];
            
            $config['image_library'] = 'gd2';
            $config['source_image'] = $data['image'];
            $config['create_thumb'] = TRUE;
            $config['maintain_ratio'] = TRUE;
            $config['width'] = 150;
            $config['height'] = 150;
            $config['new_image'] = "thumbs/".$image['file_name'];
            
            $this->load->library('image_lib', $config);
            
            $this->image_lib->resize();
            
            $data = array('upload_data' => $this->upload->data());
            
            $this->load->view('upload_suc', $data);
            
        }
    }

view
Code:
<!DOCTYPE HTML>
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Uploader&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
     &lt;?= form_open('gallery/logout')?&gt;
        &lt;input type="submit" value="Logout" /&gt;
    &lt;?=form_close();?&gt;
    &lt;?php echo $error;?&gt;

    &lt;?php echo form_open_multipart('uploadimg/upload');?&gt;

    &lt;input type="file" name="userfile" size="20" /&gt;
    <br /><br />

    &lt;input type="submit" value="upload" /&gt;

    &lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;



File upload not working - El Forum - 05-12-2009

[eluser]Dam1an[/eluser]
I'm assuming the directory obviously exists Tongue
Have you changed the file permissions to be writeable?


File upload not working - El Forum - 05-12-2009

[eluser]learning_php[/eluser]
Hi,

yea it there as i can see the contents of it if i go to www.wesayido.co.uk/uploadsand on the server it has a permission number of 0755 and when i click and go to file permissions all teh boxs are ticked.


File upload not working - El Forum - 05-12-2009

[eluser]Dam1an[/eluser]
So only the owner has write permission to the folder
It could be that on the production server, apache is being run under a diferant user group, therefore doesn;t have permission
Try changing it to 777


File upload not working - El Forum - 05-12-2009

[eluser]learning_php[/eluser]
Hi,

I have changed the permissions to 777 but i get the same error


File upload not working - El Forum - 05-12-2009

[eluser]Dam1an[/eluser]
Try here, here and here

Hope they help


File upload not working - El Forum - 05-12-2009

[eluser]tomcode[/eluser]
Try

Code:
$config['upload_path'] = './uploads/';



File upload not working - El Forum - 05-12-2009

[eluser]learning_php[/eluser]
Hi,
./uploads works on my localhost my not on the live server?

I changed the contoller to the following but i still get the same error
Code:
function upload()
    {
        // Image configuration
        $config['upload_path'] = $_SERVER['DOCUMENT_ROOT'].'uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['overwrite'] = FALSE;
        $config['max_size'] = 4048;
        
        $this->load->library('upload', $config);
        
    
        if(!$this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('upload', $error);
        }
        else
        {
            
        
            $image = $this->upload->data();
            $data['image'] = $_SERVER['DOCUMENT_ROOT'].'uploads/'.$image['file_name'];
            $config['image_library'] = 'gd2';
            $config['source_image'] = $data['image'];
            $config['create_thumb'] = TRUE;
            $config['maintain_ratio'] = TRUE;
            $config['width'] = 150;
            $config['height'] = 150;
            $config['new_image'] = $_SERVER['DOCUMENT_ROOT'].'thumbs/'.$image['file_name'];
            
            $this->load->library('image_lib', $config);
            
            $this->image_lib->resize();
            
            $data = array('upload_data' => $this->upload->data());
            
            $this->load->view('upload_suc', $data);
            
        }
    }



File upload not working - El Forum - 05-12-2009

[eluser]learning_php[/eluser]
HI,

if i change it to this
Code:
$config['upload_path'] = realpath((BASEPATH.'/images/'));
i get
Code:
The upload destination folder does not appear to be writable.



File upload not working - El Forum - 03-30-2010

[eluser]nicholas.byfleet[/eluser]
is your .htaccess file messing things up? just brainstorming here.