Make WordPress Core

Opened 8 years ago

Last modified 7 years ago

#38560 new feature request

Add support for uploading arrayed $_FILES

Reported by: kontur's profile kontur Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Media Keywords: needs-patch needs-unit-tests
Focuses: Cc:

Description (last modified by swissspidy)

When you have form code that references [several file uploads]( as array, the media_handle_upload() function fails to handle this.
For example this:

<input type="file" name="documents[]">
<input type="file" name="documents[]">

Will result in a $_FILES array that's creates subarrays shaped like so:


This will fail when passed to media_handle_upload, since the implementation does not handle this array structure nor is this documented.

Change History (5)

#1 @kontur
8 years ago

The obvious but unelegant workaround is to name each upload file input with an index or the like, and manually pick them apart before passing them separately to the media_upload_handle()

#2 @swissspidy
8 years ago

  • Description modified (diff)
  • Version 4.6.1 deleted

This ticket was mentioned in Slack in #core-media by desrosj. View the logs.

7 years ago

#4 @desrosj
7 years ago

  • Type changed from defect (bug) to enhancement

#5 @joemcgill
7 years ago

  • Keywords needs-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release
  • Summary changed from media_handle_upload() can't handle arrayed $_FILES to Add support for uploading arrayed $_FILES
  • Type changed from enhancement to feature request

Hi @kontur,

Thanks for the ticket.

The media_handle_upload function is meant to handle a single file at a time, from which it will generate and return a single attachment. If you're writing custom code, I would suggest handling the $_FILES object yourself, as you are suggesting.

See examples:

If we want to support this in WordPress core, we should add handling for multiple file outside media_handle_upload, in places like wp_ajax_upload_attachment and WP_REST_Attachments_Controller->upload_from_file().

Note: See TracTickets for help on using tickets.