Closed diegocavalletti closed 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.
SplFileInfo
rather
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
Oh.. That's cool. Can you send a pull request for that if you think it's stable enough ? .
I will do that as soon as i can
Fixed in #43
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.