"MDL-25633 Filepicker upload should display better error report"
authorDongsheng Cai <unoter@gmail.com>
Fri, 10 Dec 2010 03:16:59 +0000 (03:16 +0000)
committerDongsheng Cai <unoter@gmail.com>
Fri, 10 Dec 2010 03:16:59 +0000 (03:16 +0000)
repository/upload/lang/en/repository_upload.php
repository/upload/lib.php

index bf26483..614b219 100644 (file)
@@ -27,3 +27,10 @@ $string['configplugin'] = 'Configuration for upload plugin';
 $string['pluginname_help'] = 'Upload a file to Moodle';
 $string['pluginname'] = 'Upload a file';
 $string['upload:view'] = 'Use uploading in file picker';
+$string['upload_error_ini_size'] = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
+$string['upload_error_form_size'] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';
+$string['upload_error_partial'] = 'The uploaded file was only partially uploaded.';
+$string['upload_error_no_file'] = 'No file was uploaded.';
+$string['upload_error_no_tmp_dir'] = 'PHP is missing a temporary folder.';
+$string['upload_error_cant_write'] = 'Failed to write file to disk.';
+$string['upload_error_extension'] = 'A PHP extension stopped the file upload.';
index ef682d7..0edc42c 100755 (executable)
@@ -74,9 +74,32 @@ class repository_upload extends repository {
         if (!isset($_FILES[$elname])) {
             throw new moodle_exception('nofile');
         }
-
         if (!empty($_FILES[$elname]['error'])) {
-            throw new moodle_exception('maxbytes');
+            switch ($_FILES[$elname]['error']) {
+            case UPLOAD_ERR_INI_SIZE:
+                throw new moodle_exception('upload_error_ini_size', 'repository_upload');
+                break;
+            case UPLOAD_ERR_FORM_SIZE:
+                throw new moodle_exception('upload_error_form_size', 'repository_upload');
+                break;
+            case UPLOAD_ERR_PARTIAL:
+                throw new moodle_exception('upload_error_partial', 'repository_upload');
+                break;
+            case UPLOAD_ERR_NO_FILE:
+                throw new moodle_exception('upload_error_no_file', 'repository_upload');
+                break;
+            case UPLOAD_ERR_NO_TMP_DIR:
+                throw new moodle_exception('upload_error_no_tmp_dir', 'repository_upload');
+                break;
+            case UPLOAD_ERR_CANT_WRITE:
+                throw new moodle_exception('upload_error_cant_write', 'repository_upload');
+                break;
+            case UPLOAD_ERR_EXTENSION:
+                throw new moodle_exception('upload_error_extension', 'repository_upload');
+                break;
+            default:
+                throw new moodle_exception('nofile');
+            }
         }
 
         if (empty($saveas_filename)) {