Gargron / fileupload

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

Invalid $files after processAll() #25

Closed ghost closed 7 years ago

ghost commented 8 years ago

list($files, $headers) = $fileupload->processAll();

While uploading multiple image files, the $files array I received was wrong. It had the same value (last image data) for all array indices.

Can anyone please confirm if this is the case with everyone or just me ?

In case it's for everyone, this is a major issue and I have found a solution which I would be happy to share.

andrew951 commented 8 years ago

I am also experiencing this issue. What is the solution that you've found?

ghost commented 8 years ago

src/FileUpload/FileUpload.php

Line 281

$files is a protected array of Class FileUpload. While pushing array into $files this roughly what happened

$files[] = $this->process // Returns file object instance 1
echo $files; // files ( 0 => object 1 )

$files[] = $this->process // Reurns file object instance 2
echo $files; // files ( 0 => object 2,    1 => object 2 )

It changed all the values to the last object instance value.

Solution.

On Line 281

$this->files[] = (object)(array)$this->process( ...

Type cast the object to array, and then again to object. This way the values were retained, and not replaced.

Let me know if it worked for you too.

kaperys commented 8 years ago

Worked for me. Created PR https://github.com/Gargron/fileupload/pull/28