Welcome Guest, Not a member yet? Register   Sign In
Multi File Upload with CI
#5

[eluser]psychomarine[/eluser]
the solution was discovered on this page. Sort of unrelated of course but I discovered my problem with this.
http://ellislab.com/forums/viewthread/121434/


Now, Ill go ahead and make this easy for everyone.

The problem is, most of the tutorials and doc's tell you to do this:

Code:
public function do_upload()
    {
        $config['upload_path'] = './uploads/files/';
        $config['allowed_types'] = 'jpg|png|gif';
        $config['max_size']    = '1000';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        
        $this->load->library('upload', $config);
...and so on...

Well, out of habbit, me and many other people, like to load our things in the __construct() and keep it uniform.

I however did not realize, as many others that by doing:
Code:
public function __construct()
    {
        parent::Controller();    

        $this->load->library('upload');
        $this->load->library('form_validation');
    }

messes up when you call it a 2nd time, as shown in the first example.


Now I can only assume that codeigniter has implemented some sort of singleton method, which is smart I might add.

For those who dont know, a singleton basically allows one instance of a class to run preventing a 2nd instance from initializing. (basically because it goes alot deeper than that in some cases)


Now, what was happening was that the __contruct was loading the upload class first, ignoring any config I tried to feed into it later on.

Now, removing the initial loading of the upload class solved my issue.

There is also a second fix, as referenced in the user guide, for those who like to load everything needed in the __construct:
Code:
// Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:
$this->upload->initialize($config);

Hope this helps anyone who has issues. Its a good starting point when you think everything is correct and it just wont work properly.

It can be annoying because we KNOW it works, else theres low chances on them releasing it to the public if it doesnt work at all.

in closing, seems to be a case of "pebkac"


Thanks.


Messages In This Thread
Multi File Upload with CI - by El Forum - 10-24-2009, 03:31 AM
Multi File Upload with CI - by El Forum - 10-24-2009, 04:02 AM
Multi File Upload with CI - by El Forum - 10-24-2009, 06:02 AM
Multi File Upload with CI - by El Forum - 10-24-2009, 05:19 PM
Multi File Upload with CI - by El Forum - 10-24-2009, 07:19 PM



Theme © iAndrew 2016 - Forum software by © MyBB