Multiple files upload #6085
Replies: 18 comments
-
Jajajaa , Hello friend, you save my work...after two hours i research for php.net view the functionality of $_FILE |
Beta Was this translation helpful? Give feedback.
-
In the latest HTML file input spec, you have a multiple parameter, which you can set to true to select more than one file to upload at a time. I took this code and it almost worked, but I had to call initialize every time as it couldn't use the upload path, which meant I also needed to pass in the configuration (though there's probably a slick way to pull it in as a subclass). public function do_multiple_upload($field = 'userfile', $config = array() ) {
$files = $_FILES; // we would change $_FILES so we need a copy
$flag = false; // flag indicates if at least one upload was successful
for($i = 0; $i < count($files[$field]['name']); $i++) { // for each file
// setting up $_FILES so it looks like we uploaded single file
foreach($files[$field] as $attr => $values) {
$_FILES[$field][$attr] = $values[$i];
}
// performing upload and updating flag
$this->initialize($config);
$res = $this->do_upload($field);
$flag = $flag || $res;
// saving upload's data (it can later be fetched using get_data()
array_push($this->multiple_upload_data, $this->data());
}
return $flag;
} |
Beta Was this translation helpful? Give feedback.
-
It looks like this could be profitably added to the file uploading class (libraries/upload). |
Beta Was this translation helpful? Give feedback.
-
This is an unnecessary change,It's very easy to handle multiple uploads, default is better(brings more control) |
Beta Was this translation helpful? Give feedback.
-
I think codeigniter must have a multiple upload in the next release. Te class CI_Upload should have do_upload() method and do_multiple_upload() method. Once uploaded files $this->upload->data() method should return an associative array with the information of each file. |
Beta Was this translation helpful? Give feedback.
-
Why has this been made "won't fix"? It still needs fixing. I can't believe I am still having to extend the upload class... If people are struggling to write this here is a nice example: https://github.com/avenirer/MY_Upload |
Beta Was this translation helpful? Give feedback.
-
in my opinion it is shame in 2015 and with good framework like codeigniter to discuss if we accept or not accept to add multiupload... so i support this request with @pleaseremove |
Beta Was this translation helpful? Give feedback.
-
You know what's a shame? That even in 2016 people like you will come here complaining that the framework isn't adding tens of lines of code for something that you can do by simply wrapping We're not discussing this; it's rejected and that's why it has the "Won't Fix" label. The issue has been kept open just so you don't open new ones about the same thing. |
Beta Was this translation helpful? Give feedback.
-
people like me don't waste their times to write basics and understand the DRY concept and if framework like codeigniter doesn't support this basics it will be shame :) |
Beta Was this translation helpful? Give feedback.
-
I hate going off-topic on stupid shit, but I also hate it when people talk nonsense and I especially hate it when every refusal to implement a shorthand for something is met with "blah blah blah DRY blah blah". If you truly understood the DRY concept, you would know that it stands for "Don't Repeat Yourself". So please explain to me, how is implementing a
And last but not least, DRY, KISS and whatever other catchy-name principles you can think of, are not the holy grail of programming and must not be followed blindly. There's always context to have in mind and you must always, always know why you're doing something. |
Beta Was this translation helpful? Give feedback.
-
@davidgv88 Your last comment didn't accidentally disappear, I deleted it. This isn't StackOverflow ... we're not looking for a 3 pages long snippet of how to do something. |
Beta Was this translation helpful? Give feedback.
-
@narfbg OK! |
Beta Was this translation helpful? Give feedback.
-
I do take your point @narfbg and clearly whatever you decide is what will happen so that is fair enough. The way I normally extend what is there (and as such what I would be after) is support for the "multiple" attribute. Aka, the do upload would perform as normal, but if there were multiple files under that field name, spit out an array of results. I accept there are complications like what to do if there is a single failure in a mix of 3 or 4 files etc, but personally I find most of my apps need to support multiple files. Thanks |
Beta Was this translation helpful? Give feedback.
-
@pleaseremove Codeigniter by default not support upload files with "multiple" attribute. The Solution with "multiple" attribute is this:
|
Beta Was this translation helpful? Give feedback.
-
Has this been implemented yet? This looks just like the thing I need for our system. Looping is such a hassle and strain on resources. |
Beta Was this translation helpful? Give feedback.
-
According to the DRY principle we shouldn't have to write for loops every time we want to implement multiple file uploads. Besides that it keeps code clean if it's centralised. Waiting for this to implemented. |
Beta Was this translation helpful? Give feedback.
-
TL;DR: There is nothing left to be contributed to this thread and it has already been decided that this is not going to be implemented. Here's a few reasons why (the list is not exhaustive):
The decision won't change. I'm permanently locking the thread to avoid more pointless messages.
Yes, but we like to troll people by keeping issues open and with the "Won't Fix" label applied.
I agree, looping does take hours to implement. And it takes up so much resources, which would magically go away if the framework did the looping instead of you.
Indeed, the DRY principle does explicitly say that
To the possibly offended by this comment: If you can't be bothered to read the thread you are replying to (not even the last few comments, nor even its very visible labels), then you cannot reasonably expect a nice answer either. No offense meant; that's just how it works and I like sarcasm. |
Beta Was this translation helpful? Give feedback.
-
Hi!
For one of projects I needed multiple files upload so I extended CI_Upload with two functions: do_multiple_upload() and get_data() (that are equivalents of do_upload() and data() respectively but for multiple files). My extension uses dirty hack with substituting $_FILES contents and calling do_upload(), but that's the best way I can think of (duplicating whole class or just do_upload() is much worse).
Maybe that feature is important enough to add to CI, or maybe someone would just find my code useful, so here it is:
Thank you for developing Code Igniter!
Beta Was this translation helpful? Give feedback.
All reactions