Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Make FileException more detailled (or split exception) #26411

Copy link
Copy link
Closed
@soullivaneuh

Description

@soullivaneuh
Issue body actions
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:

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:

  1. The simplest one: Add the PHP error constant on the FileException to make it accessible from the catch.
  2. The best (IMO): Create new exception based on the PHP error constant such as IniSizeFileException or FormSizeFileException.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.