-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
[HttpFoundation] Add UploadedFile::getClientOriginalPath()
to support directory uploads
#52493
Conversation
FileBag
full_path
in FileBag
That's a new feature for sure so for 7.1 |
I haven't contributed to the form component yet, so I will check it out. Should be fairly simple though. |
I just realized that merging this should break many legacy test cases where a file upload is manually submitted. Even though it is more work than simply making this option optional in FileBag, these tests SOULD be fixed because they do not adhere to the default PHP behaviour and in my opinion the FileBag should not account for that. It would also require to rework the entire logic of the FileBag. |
See this answer from stof: #52528 (comment) |
full_path
in FileBag
FileBag::getClientOriginalFullPath()
to support directory uploads
FileBag::getClientOriginalFullPath()
to support directory uploadsFileBag::getClientOriginalPath()
to support directory uploads
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this. I played a bit with the code+feature, here are my comments.
FileBag::getClientOriginalPath()
to support directory uploadsUploadedFile::getClientOriginalPath()
to support directory uploads
I think the failure on |
Yeah, this failure is related. Like I mentioned here, pretty much every test that submits a file upload manually will fail now and will have to be migrated because they don't include the This is standard PHP behaviour since 8.1 and thats also the minimum required PHP version now. So I don't really see the "point" in supporting these legacy cases and they should be updated to include If it is the teams desire to keep this legacy behaviour, the logic of FileBag has to be heavily modified because it requires that every possible "file key" in $_FILES is included. IMO fixing all of these test cases should be a separate PR which I'm willing to create after this is merged. |
I think we could support it more gracefully by using However, it might be great to update the tests emulating file uploads to include this |
I had a quick look at where files are submitted manually and what tests will have to be fixed:
It looks like these aren't that many and we can literally just copy the value BrowserKit/DomCrawler also submits files but their logic seem to be independant. I also discovered |
I think updating NativeRequestHandler in this PR makes sense as well. |
Adding something like the following in FileBag should in theory work: protected function convertFileInformation(array|UploadedFile $file): array|UploadedFile|null
{
if ($file instanceof UploadedFile) {
return $file;
}
if (!\array_key_exists('full_path', $file) && \array_key_exists('name', $file)) {
$file['full_path'] = $file['name'];
}
// ...
} This should then both work with "fixed file arrays and "normal" ones. |
…rt directory uploads
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed an alternative implementation that should fix BC issues.
Thank you @danielburger1337. |
…ath()` to support directory uploads (danielburger1337) This PR was squashed before being merged into the 7.1 branch. Discussion ---------- [HttpFoundation] Add `UploadedFile::getClientOriginalPath()` to support directory uploads See #19212 and symfony/symfony#52493 Edit: I just realized that `@alexandre`-daubois created PR #19215 for this as well. Just for the record, I don't care which one gets merged. Commits ------- 4120857 [HttpFoundation] Add `UploadedFile::getClientOriginalPath()` to support directory uploads
This removes the "hotfix" #42112 and now supports "full_path" PHP file uploads.
Since PHP 8.1 is now the lowest allowed version of PHP, this shouldnt cause any problems.
Although I'm quite certain that I understand the messy FileBag code, I'm very concerned for the potential impact this change might have because of the widespread use of http-foundation.
To the best of my knowledge, this won't break Symfony BC (yet) because this is all done by an
optional
argument in the constructor of UploadedFile (this should eventually be replaced by a mandatory argument though).Also, I'm not quite happy with the tests. Since this is only a "passthrough" of the PHP value, this shouldnt be a huge problem.
Someone should definitly go through this change very carefully. The tests pass and I also threw some "real world" application tests at it and everything seems to work just fine. But because of the nature of HttpFoundation and its intangled mess, I can't guarantee that I accounted for every possible or even simple edge case.
Though it would be nice to still see this in 7.0, I know that it will probably be pushed back to 7.1.