Don't fail, if filenames are too long, shorten them instead #42
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.
Summary of Changes
The length of filenames is restricted to 250 characters,
move_uploaded_files()
already fails with length above 247 characters.(as stated in a comment in the PHP manual).With this PR, filenames (i.e., the basename plus the extension) are shortend to 240 characters, if their length exceed that length with the
File::makeSafe()
method. The directory and the extension are preserved.Changes affecting tests only:
Testing Instructions
The change is covered by unit tests.
Call
File::makeSafe()
with a filename with more than 240 characters. The result should be a sanitised version of the filename with a maximum length of 240 characters.Documentation Changes Required
Probably.