[Solved] Upload library issue |
Hi. I'm having a bit of an issue with the upload library, and I would appreciate some help with it.
In essence, if I try to upload files from several inputs in the same function, I get either of two errors, depending on how I initialize the upload of any input following the first one. If I initialize it using $this->upload->initialize($config) or $this->upload->initialize($config,TRUE), and the $config array for the previous input has something set up for the first input (ie allowed_types) while the second one shouldn't (ie if the second input shouold accept any file type), I get the following error: Code: You have not specified any allowed file types. If, on the other hand, I initialize it using $this->upload->initialize($config,FALSE), assuming the previous one had $config['allowed_types'] = "jpg", the second one would only accept jpgs, and would return the following error if something else was provided, even if it should accept any file type: Code: The filetype you are attempting to upload is not allowed. While what I'm making is a bit more complex than this, a barebones example would look like this. Let's say I have two file inputs. The first one, name="idcard", is a common file input, and should only take an image up to 10MB in filesize. The second one, name="portfolio", has a multiple="multiple" flag set, should take any file type but up to 10MB in filesize, and would be limited to 20 files. The controller looks like this: Code: function uptest() { Code: <?php If I have it as $this->upload->initialize($config) or $this->upload->initialize($config,TRUE), I get a "You have not specified any allowed file types. The filetype you are attempting to upload is not allowed" error regardless, returning it an incremental number of times per file. Any help would be much appreciated. Thanks in advance.
No one?
In the meantime, I tried three things: 1 - unsetting the upload library and setting it again (as Code: unset($this->upload) 2 - creating an unload extension to the loader, using the first answer here, https://stackoverflow.com/questions/22209209 , and 3 - adding a third parameter when loading the class to apparently avoid collisions (by doing Code: $this->load->library('upload',$config,"idup") Code: $this->idup->do_upload('idcard') ... and no cigar. Same "The filetype you are attempting to upload is not allowed. You have not specified any allowed file types." error, except for the loader extension, which returns "Undefined property: MY_Loader::$_ci_loaded_files" instead. So yeah, any help would be really appreciated. To make it easier to test for anyone willing to, I isolated the controller and the view, which can be downloaded here: https://a.pomf.cat/gonuie.zip Copying them to /controllers and /views as in the folders and accessing //:localhost/project/uptest should have it running, errors and all. Thanks.
... and I solved it.
Turns out allowed_types appears to be required (had the brilliant idea to comment out the allowed_types line to see what errors I got, and the same one popped up for the first upload too), so as I wanted to accept any file type in the second input, I had to set Code: $config['allowed_types'] = '*' A single argument had me running like a headless chicken for a few days. Dang. Anyway, it's solved now. Sorry about the clutter. |
Welcome Guest, Not a member yet? Register Sign In |