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

[BUG] Phalcon\Http\Request::hasFiles() and getUploadedFiles() do not work with file arrays #888

Merged
merged 10 commits into from Jul 22, 2013

Conversation

ghost
Copy link

@ghost ghost commented Jul 19, 2013

See #878, #884 — this fixes them.

For #878: if we have a file array like this:

<p>file1:<input type="file" name="photo[]"></p>
<p>file2:<input type="file" name="photo[]"></p>
<p>file3:<input type="file" name="photo[][]"></p>
<p>file4:<input type="file" name="photo[][]"></p>
<p>file5:<input type="file" name="photo[][][]"></p>
<p>file6:<input type="file" name="photo[][][][][]"></p>

the keys will be:

  • photo.0
  • photo.1
  • photo.2.0
  • photo.3.0
  • photo.4.0.0
  • photo.5.0.0.0.0

Main features:

  • Phalcon\Http\Request::hasFiles() understands file arrays and returns correct number of uploaded files
  • Phalcon\Http\Request::getUploadedFiles() understands file arrays

Also:

  • added getKey() method to Phalcon\Http\Request\File
  • key is passed as an optional second parameter to Phalcon\Http\Request\File::__construct()
  • added getError() method to Phalcon\Http\Request\File (can be useful when all files are retrieved, not only those uploaded successfully)
  • added __set_state() and isUploadedFile() methods to Phalcon\Http\Request\File (the first one is meant for testing, the second one can be used to make sure that the file was really uploaded to the server and $_FILES is not forged)

Suggestions:

  • getUploadedFiles() should probably return an associative array, the key being the second argument to Phalcon\Http\Request\File::__construct(). I don't think this will break the existing implementations.
  • add getKey(), getError() and possibly isUploadedFile() to Phalcon\Request\FileInterface

@dreamsxin
Copy link
Contributor

You are Superman。
Not automatically merge. Lost key, Manually merge.

@ghost
Copy link
Author

ghost commented Jul 22, 2013

Rebased against the latest HEAD

phalcon pushed a commit that referenced this pull request Jul 22, 2013
[BUG] Phalcon\Http\Request::hasFiles() and getUploadedFiles() do not work with file arrays
@phalcon phalcon merged commit 3fba27a into phalcon:1.2.1 Jul 22, 2013
@phalcon
Copy link
Collaborator

phalcon commented Jul 22, 2013

Thanks guys

@ghost ghost deleted the hasfiles-nested branch July 22, 2013 15:54
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

Successfully merging this pull request may close these issues.

3 participants