Browse files

"MDL-25633 Filepicker upload should display better error report"

  • Loading branch information...
1 parent 2b574cc commit 1298a119357c5db978d55185b2db725ace01f9a6 @dcai dcai committed Dec 10, 2010
Showing with 32 additions and 2 deletions.
  1. +7 −0 repository/upload/lang/en/repository_upload.php
  2. +25 −2 repository/upload/lib.php
View
7 repository/upload/lang/en/repository_upload.php
@@ -27,3 +27,10 @@
$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.';
View
27 repository/upload/lib.php
@@ -74,9 +74,32 @@ public function upload($saveas_filename, $maxbytes) {
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)) {

0 comments on commit 1298a11

Please sign in to comment.