-
-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup uploaded files for PSR-15 handlers
- Loading branch information
Showing
2 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If you're not planning to delete files at the end of the current request - where you still have the precise filenames - but rather at the beginning of the next one, I recommend using a stricter RegEx for
glob
to minimize the risk of deleting unintended files.Since
tempnam
generates files with a 6-character long alphanumeric suffix, you can create a more preciseglob
pattern like this:$tmpFiles = glob(sys_get_temp_dir() . '/' . self::UPLOADED_FILES_PREFIX . '[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]');
I know it's ugly but AFAIK you can't do
[A-Za-z0-9]{6}
inglob
.