Implement file uploads for PATCH and PUT requests #18

Merged
merged 1 commit into from May 31, 2014

Conversation

Projects
None yet
1 participant
Owner

weierophinney commented May 31, 2014

multipart/form-data is natively supported via POST by PHP. However, PATCH
and PUT are not; you need to parse the request body and separate the parts
into:

  • form data
  • file uploads

Additionally, for each file upload, you need to mimic how PHP uploads files,
and create a $_FILES compatible array.

This patch does the following:

  • Adds support for parsing multipart/form-data request bodies, via
    Zend\Mime.
  • Injects any discovered form data parameters into the
    ParameterDataContainer,
    making them available later via the bodyParam*() plugins.
  • Performs file uploads on any discovered files. This involves creating a
    temporary file in either the upload_tmp_dir or system temporary directory
    (depending on current configuration). Files are created using the prefix
    zfc
    to make them identifiable later. A $_FILES-compatible entry is created for
    each upload, and injected into the response's files container.
  • If any file uploads were discovered, it registers a listener on the "finish"
    event to remove any files still remaining. The assumption is that you will
    move or rename any upload files.
@weierophinney weierophinney Implement file uploads for PATCH and PUT requests
`multipart/form-data` is natively supported via POST by PHP. However, PATCH and
PUT are not; you need to parse the request body and separate the parts into:

- form data
- file uploads

Additionally, for each file upload, you need to mimic how PHP uploads files, and
create a `$_FILES` compatible array.

This patch does the following:

- Adds support for parsing `multipart/form-data` request bodies, via
  `Zend\Mime`.
- Injects any discovered form data parameters into the `ParameterDataContainer`,
  making them available later via the `bodyParam*()` plugins.
- Performs file uploads on any discovered files. This involves creating a
  temporary file in either the `upload_tmp_dir` or system temporary directory
  (depending on current configuration). Files are created using the prefix `zfc`
  to make them identifiable later. A `$_FILES`-compatible entry is created for
  each upload, and injected into the response's files container.
- If any file uploads were discovered, it registers a listener on the "finish"
  event to remove any files still remaining. The assumption is that you will
  move or rename any upload files.
ddd9511

weierophinney added this to the 1.0.2 milestone May 31, 2014

@weierophinney weierophinney merged commit ddd9511 into zfcampus:master May 31, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

@weierophinney weierophinney added a commit that referenced this pull request May 31, 2014

@weierophinney weierophinney Merge branch 'feature/multipart-form-data'
Close #18
6a5e2a9

weierophinney deleted the weierophinney:feature/multipart-form-data branch May 31, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment