[11.x] Fix client path value in file uploads #53941
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PHP 8.1 introduced the 'full_path' key in $_FILES during file uploads. The purpose is to support Folder uploads.
Symphony handles this. When a new instance of UploadedFile is created, $file['full_path'] ?? $file['name'] is passed to it
originalPath is set to the full value -> /path/filename.txt -> getClientOriginalPath()
originalName is set to the file name after extracting it from the full_path (if needed) // filename.txt
Laravel doesn't handle this change.
InteractsWithInput.php file:
convertUploadedFiles() is defined. "Convert the given array of Symfony UploadedFiles to custom Laravel UploadedFiles."
convertUploadedFiles calls UploadedFile::createFromBase($file). This is where the Issue lies (UploadedFile.php ln 144)
A new instance of uploadedFile is created using the 'getClientOriginalName' causing us to lose the 'full_path' value. Which was stored in getClientOriginalPath()
Note: path here is not the temporary path. Not the uploadedTo path. But the original path sent by the client in the full_path key.
My fix: is to use getClientOriginalPath() instead. I think it should be okay. Since symfony extracts the originalname from the full_path.
This is my first attempt of such a PR. Please do tell if I have missed anything.
Thank you!