Welcome Guest, Not a member yet? Register   Sign In
Please explain UPLOAD strange error
#1

[eluser]Yash[/eluser]
May be I'm missing something but it looks some kind of bug to me.


Working Code

Code:
<?php

class Upload extends Controller {

    function Upload()
    {
        parent::Controller();
        $this->load->helper(array('form', 'url'));
    }
    
    function index()
    {    
        echo realpath('uploads');
        $this->load->view('upload/upload_view', array('error' => ' ' ));
    }

    function do_upload()
    {
        $config['upload_path'] = realpath('uploads');
        $config['allowed_types'] = 'gif|jpg|png|docx|doc|pdf|zip|rar|txt|rtf|psd';
        $config['max_size']    = '5000';
        $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/upload_view', $error);
        }    
        else
        {
            $data = array('upload_data' => $this->upload->data());
            
            $this->load->view('upload/success_view', $data);
        }
    }    
}
?>

Not working

Code:
<?php

class Upload extends Controller {
    
    function Upload()
    {
        parent::Controller();
        $this->load->helper(array('form', 'url'));
    }
    
    function index()
    {    
        $this->load->view('upload_form', array('error' => ' ' ));
        echo realpath('uploads') ;
    }

    function do_upload()
    {
        $this->load->library('upload');
    
        $config['upload_path'] =realpath('uploads');
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '100';
        $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->load->view('upload_success', $data);
        }
    }    
}
#2

[eluser]Yash[/eluser]
Giving Error ...uploaded path is not correct
#3

[eluser]xwero[/eluser]
Does the directory have sufficient rights to upload a file to?
#4

[eluser]Yash[/eluser]
Testing on windows server.

First controller uploads the files while second controller gave error. Rest(views) is same.
#5

[eluser]xwero[/eluser]
Oh yes it's the common newbie mistake of loading a library more than once. You have to use initialize in your not working class.
Code:
$this->load->library('upload', $config);
change to
Code:
$this->upload->initialize($config);
#6

[eluser]Yash[/eluser]
wow thats superb for me.. Thank you




Theme © iAndrew 2016 - Forum software by © MyBB