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

$_FILES array with multiple file uploads #1006

Closed
stoph opened this issue Feb 6, 2024 · 2 comments · Fixed by #1018
Closed

$_FILES array with multiple file uploads #1006

stoph opened this issue Feb 6, 2024 · 2 comments · Fixed by #1018
Assignees

Comments

@stoph
Copy link
Contributor

stoph commented Feb 6, 2024

Normal single uploads via name="photo" seem to work, but when you enable multiple by using name="photos[]" (but still only upload one file) the $_FILES array looks to be inverted.

Array
(
  [photos] => Array
    (
      [0] => Array
        (
          [name] => logo.png
        )

      [1] => Array
        (
          [tmp_name] => /tmp/0.71939801482611698269
        )

      [2] => Array
        (
          [type] => image/png
        )

      [3] => Array
        (
          [error] => 0
        )

      [4] => Array
        (
          [size] => 8192
        )
    )
)

It should be [photos][name][0] not [photos][0][name]

Array
(
  [photos] => Array
    (
      [name] => Array
        (
          [0] => logo.png
        )

      [tmp_name] => Array
        (
          [0] => /tmp/0.71939801482611698269
        )

      [type] => Array
        (
          [0] => image/png
        )

      [error] => Array
        (
          [0] => 0
        )

      [size] => Array
        (
          [0] => 8192
        )
    )
)

And related, when I try to upload more than one file at a time, the browser hangs as (pending) with this error from wp-now.

Trace: TypeError: Cannot read properties of undefined (reading 'buffer')
    at Object.arrayBuffer (file:///Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/main.js:894:46)
    at #dispatchToPHP (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:68550:45)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async PHPRequestHandler.request (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:68484:14)
    at async PHPBrowser.request (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:68326:22)
    at file:///Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/main.js:908:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
@bgrgicak bgrgicak self-assigned this Feb 6, 2024
@bgrgicak
Copy link
Collaborator

bgrgicak commented Feb 7, 2024

@stoph @adamziel what would be a good way to recreate this?
I can try writing some tests, but I would still like to have a way to test it on the site.

@stoph
Copy link
Contributor Author

stoph commented Feb 7, 2024

I created a super simple plugin to echo the array after an upload.

If you upload one file, it'll show the (inverted) array. It fails on multiple uploads though. To see that error, I was testing locally on wp-now and viewing the wp-now start terminal output. You can download the plugin here)

adamziel added a commit that referenced this issue Feb 8, 2024
Removes the custom file upload handler and rely on PHP body parsing
to populate the $_FILES array. Instead of encoding the body bytes as
a string, parsing that string, and re-encoding it as bytes, we keep
the body in a binary form and pass it directly to PHP HEAP memory.

Closes #997
Closes #1006
Closes #914

 ## Testing instructions

Confirm the CI checks pass (it will take a few iterations to get them right I'm sure :D)
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 a pull request may close this issue.

2 participants