From 1d951cb793eae06962cdd3763374b598de508423 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Tue, 3 Nov 2009 02:21:47 +0000 Subject: [PATCH] More extensive patch to MDL-20922 --- lib/file/file_exceptions.php | 44 ++++++++++++++++++++++++++++++++ repository/upload/repository.class.php | 2 +- 2 files changed, 45 insertions(+), 1 deletions(-) diff --git a/lib/file/file_exceptions.php b/lib/file/file_exceptions.php index 78d5c98..076db47 100644 --- a/lib/file/file_exceptions.php +++ b/lib/file/file_exceptions.php @@ -65,3 +65,47 @@ class file_pool_content_exception extends file_exception { parent::__construct('hashpoolproblem', $contenthash, $debuginfo); } } + +/** + * Hash upload exception + */ +class file_upload_exception extends file_exception { + function __construct($errorcode){ + + $string = ''; + switch ($errorcode) { + case 0: // UPLOAD_ERR_OK - no error + debugging('File upload exception created without an exception code', DEBUG_DEVELOPER); + break; + case 1: // UPLOAD_ERR_INI_SIZE + $string = 'uploadserverlimit'; + break; + case 2: // UPLOAD_ERR_FORM_SIZE + $string = 'uploadformlimit'; + break; + case 3: // UPLOAD_ERR_PARTIAL + $string = 'uploadpartialfile'; + break; + case 4: // UPLOAD_ERR_NO_FILE + $string = 'uploadnofilefound'; + break; + + // Note: there is no error with a value of 5 + + case 6: // UPLOAD_ERR_NO_TMP_DIR + $string = 'uploadnotempdir'; + break; + case 7: // UPLOAD_ERR_CANT_WRITE + $string = 'uploadcantwrite'; + break; + case 8: // UPLOAD_ERR_EXTENSION + $string = 'uploadextension'; + break; + + default: + $string = 'uploadproblem'; + } + + parent::__construct($string); + } +} diff --git a/repository/upload/repository.class.php b/repository/upload/repository.class.php index 920f4e3..2cd27ca 100755 --- a/repository/upload/repository.class.php +++ b/repository/upload/repository.class.php @@ -94,7 +94,7 @@ class repository_upload extends repository { } if (!empty($_FILES[$elname]['error'])) { - throw new moodle_exception(file_get_upload_error($_FILES[$elname]['error'])); + throw new file_upload_exception($_FILES[$elname]['error']); } if (!$filename) { -- 1.5.6.5