Skip to content

fix: make multipart file uploads work - #16

Merged
nlemoine merged 1 commit into
mainfrom
fix/multipart-upload
Nov 26, 2026
Merged

nlemoine merged 1 commit into
mainfrom
fix/multipart-upload

Conversation

@nlemoine

Copy link
Copy Markdown
Owner

Any multipart part with a filename failed with Failed to serialize globals data: Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed. $_FILES was filled with the UploadedFile objects from the Symfony request, and they can't be serialized for the child process. The client now sends the array a web server puts in $_FILES (name, full_path, type, tmp_name, error, size).

Fixing that alone is not enough for most apps, because the CLI SAPI has no real uploads. is_uploaded_file() returns false and move_uploaded_file() refuses to move, and frameworks like Symfony go through them. The runtime now replaces both functions, the same way it already replaces header() (disabled with disable_functions, redefined in functions.php). They only accept the temporary files the client wrote for this request, recorded before the script runs, so a script cannot use move_uploaded_file() to move any other file.

The upload tests in ClientRequestTest caught every exception and had their assertions behind if guards, so they passed while uploads were broken. They now assert the name, type, size and contents seen by the script, MIME detection from the contents, and moving the file. 6 of the new tests fail on main.

A part name like files[] is still not expanded into nested arrays as PHP does for real uploads. I noted it in the README, it was already the case.

Any multipart part with a filename failed: $_FILES held Symfony
UploadedFile objects, which can't be serialized for the child process.
The client now sends the array a web server would put in $_FILES.

The CLI SAPI has no real uploads, so is_uploaded_file() and
move_uploaded_file() refused every file, and frameworks reject uploads
through them. The runtime now replaces both, the same way as header(),
and accepts the temporary files the client wrote for this request
only, so a script can't use them to move arbitrary files.

The upload tests caught every exception and passed anyway. They now
assert the uploaded name, type, size and contents, MIME detection, and
moving the file.
@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.05882% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.59%. Comparing base (01ce431) to head (ea55afc).

Files with missing lines Patch % Lines
src/Runtime/UploadedFiles.php 95.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main      #16      +/-   ##
============================================
+ Coverage     93.51%   93.59%   +0.08%     
- Complexity      575      590      +15     
============================================
  Files            16       17       +1     
  Lines          1341     1374      +33     
============================================
+ Hits           1254     1286      +32     
- Misses           87       88       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nlemoine
nlemoine merged commit 2cde307 into main Nov 26, 2026
14 checks passed
@nlemoine
nlemoine deleted the fix/multipart-upload branch November 26, 2026 13:08
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.

1 participant