-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Labels
Description
Q | A |
---|---|
Bug report? | no |
Feature request? | yes |
BC Break report? | no |
RFC? | no |
Symfony version | 3.4.4 |
If an uploaded file encounter an error, a FileException
instance like this is thrown:
The file "5MB.zip" exceeds your upload_max_filesize ini directive (limit is 2048 KiB).
The message template is choose thanks to this code part:
symfony/src/Symfony/Component/HttpFoundation/File/UploadedFile.php
Lines 259 to 265 in a8dc953
UPLOAD_ERR_INI_SIZE => 'The file "%s" exceeds your upload_max_filesize ini directive (limit is %d KiB).', | |
UPLOAD_ERR_FORM_SIZE => 'The file "%s" exceeds the upload limit defined in your form.', | |
UPLOAD_ERR_PARTIAL => 'The file "%s" was only partially uploaded.', | |
UPLOAD_ERR_NO_FILE => 'No file was uploaded.', | |
UPLOAD_ERR_CANT_WRITE => 'The file "%s" could not be written on disk.', | |
UPLOAD_ERR_NO_TMP_DIR => 'File could not be uploaded: missing temporary directory.', | |
UPLOAD_ERR_EXTENSION => 'File upload was stopped by a PHP extension.', |
The issue is we don't have any access to the related PHP constant and we have to check the exception compare with string comparison which is not really reliable.
Two solutions:
- The simplest one: Add the PHP error constant on the
FileException
to make it accessible from the catch. - The best (IMO): Create new exception based on the PHP error constant such as
IniSizeFileException
orFormSizeFileException
.
What do you think?