Gargron / fileupload

PHP FileUpload library that supports chunked uploads
MIT License
460 stars 87 forks source link

Processing multiple uploads #40

Closed diegocavalletti closed 7 years ago

diegocavalletti commented 7 years ago

It looks like that when i set the input type file to "multiple" i get an array of stdClass when processing file. I was kinda surprised of that, since the documentation states that you have: foreach($files as $file){ echo $file->getRealPath(); var_dump($file->isFile()); //you can call any method on an \SplFileInfo instance} So i digged into the code, FileUpload.php -> processAll() has this:

$this->files[] = (object)(array)$this->process( $tmp_name, $upload['name'][$index], $size ? $size : $upload['size'][$index], $upload['type'][$index], $upload['error'][$index], $index, $content_range );

I find it very unconvenient to cast an SplFileInfo to array and then back to sdtClass. Woudn't it much better to just keep the original object instance?

The fix was here: https://github.com/Gargron/fileupload/issues/25 but i think that's not a good solution

Edit: a more deep inspection made me question about this: protected function process($tmp_name, $name, $size, $type, $error, $index = 0, $content_range = null) { $file = $this->fileContainer = new File($tmp_name);

I think that to fix the problem once for all we shoudn't replace $this->fileContainer with the new file instance, instead we could just replace it just once when $index == 0, so that we keep all the mechanics for single upload but we keep the strong SplFileInfo for multiple uploads since then we can fix $this->files[] = (object)(array)$this->process( with $this->files[] = $this->process(

Please tell me if I'm missing some of the logic behind that.

adelowo commented 7 years ago

Nice catch.. I'd take a look at this.

The SplInfo was a recent addition and I didn't take that into consideration.

adelowo commented 7 years ago

SplFileInfo rather

diegocavalletti commented 7 years ago

I have created a separated file copying yours and fixed to fit my need, i'm still in dev-phase, i'll let you know if i find any problem with that. So far my solution looks stable

adelowo commented 7 years ago

Oh.. That's cool. Can you send a pull request for that if you think it's stable enough ? .

diegocavalletti commented 7 years ago

I will do that as soon as i can

Edit: https://github.com/Gargron/fileupload/pull/42

adelowo commented 7 years ago

Fixed in #43