Skip to content

Commit

Permalink
"MDL-25633 Filepicker upload should display better error report"
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongsheng Cai committed Dec 10, 2010
1 parent 2b574cc commit 1298a11
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
7 changes: 7 additions & 0 deletions repository/upload/lang/en/repository_upload.php
Expand Up @@ -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.';
27 changes: 25 additions & 2 deletions repository/upload/lib.php
Expand Up @@ -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)) {
Expand Down

0 comments on commit 1298a11

Please sign in to comment.