From 735847865c243152e3ff1a0158c4ce9fff6dba6c Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 16 Aug 2011 12:37:50 -0700 Subject: [PATCH] Improve error messages when hitting PHP file upload issues Summary: See T429. When you hit certain errors, you get less-than-helpful messages like "upload error 3". Instead, produce human-readable errors. Test Plan: Simulated errors, verified user receives decent error messages. Reviewed By: aran Reviewers: jungejason, tuomaspelkonen, aran, startupguy CC: aran Differential Revision: 816 --- src/__phutil_library_map__.php | 1 + .../upload/PhabricatorFileUploadException.php | 43 +++++++++++++++++++ .../files/exception/upload/__init__.php | 12 ++++++ .../files/storage/file/PhabricatorFile.php | 2 +- .../files/storage/file/__init__.php | 1 + 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/applications/files/exception/upload/PhabricatorFileUploadException.php create mode 100644 src/applications/files/exception/upload/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 527a3ffaa3..0824b0a5ba 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -420,6 +420,7 @@ phutil_register_library_map(array( 'PhabricatorFileTransformController' => 'applications/files/controller/transform', 'PhabricatorFileURI' => 'applications/files/uri', 'PhabricatorFileUploadController' => 'applications/files/controller/upload', + 'PhabricatorFileUploadException' => 'applications/files/exception/upload', 'PhabricatorFileViewController' => 'applications/files/controller/view', 'PhabricatorGarbageCollectorDaemon' => 'infrastructure/daemon/garbagecollector', 'PhabricatorGoodForNothingWorker' => 'infrastructure/daemon/workers/worker/goodfornothing', diff --git a/src/applications/files/exception/upload/PhabricatorFileUploadException.php b/src/applications/files/exception/upload/PhabricatorFileUploadException.php new file mode 100644 index 0000000000..d48e2a4e36 --- /dev/null +++ b/src/applications/files/exception/upload/PhabricatorFileUploadException.php @@ -0,0 +1,43 @@ + + "Uploaded file is too large: file is larger than the ". + "'upload_max_size' setting in php.ini.", + UPLOAD_ERR_FORM_SIZE => + "File is too large.", + UPLOAD_ERR_PARTIAL => + "File was only partially transferred, upload did not complete.", + UPLOAD_ERR_NO_FILE => + "No file was uploaded.", + UPLOAD_ERR_NO_TMP_DIR => + "Unable to write file: temporary directory does not exist.", + UPLOAD_ERR_CANT_WRITE => + "Unable to write file: failed to write to temporary directory.", + UPLOAD_ERR_EXTENSION => + "Unable to upload: a PHP extension stopped the upload.", + ); + + $message = idx($map, $code, "Upload failed: unknown error."); + parent::__construct($message, $code); + } +} diff --git a/src/applications/files/exception/upload/__init__.php b/src/applications/files/exception/upload/__init__.php new file mode 100644 index 0000000000..23443df07a --- /dev/null +++ b/src/applications/files/exception/upload/__init__.php @@ -0,0 +1,12 @@ +