Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid $files after processAll() #25

Closed
ghost opened this issue Feb 28, 2016 · 3 comments
Closed

Invalid $files after processAll() #25

ghost opened this issue Feb 28, 2016 · 3 comments

Comments

@ghost
Copy link

ghost commented Feb 28, 2016

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
Copy link

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

@ghost
Copy link
Author

ghost commented Mar 12, 2016

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.

@ghost ghost closed this as completed Mar 12, 2016
@ghost ghost reopened this Mar 12, 2016
@kaperys
Copy link
Contributor

kaperys commented Jul 21, 2016

Worked for me. Created PR #28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants