Skip to content
Browse files

MDL-30496 fix upload max size issue when server limit is set + return…

… some kind of json error object for filenameexists and oversizedfile errors
  • Loading branch information...
1 parent 6416c6c commit 3b40f3b1a76326924456ee85c881ea242b816c6a @mouneyrac mouneyrac committed with nebgor Dec 1, 2011
Showing with 5 additions and 7 deletions.
  1. +5 −7 webservice/upload.php
View
12 webservice/upload.php
@@ -82,9 +82,10 @@
$file = new stdClass();
$file->filename = clean_param($_FILES[$fieldname]['name'], PARAM_FILE);
// check system maxbytes setting
- if (($_FILES[$fieldname]['size'] > $CFG->maxbytes)) {
+ if (($_FILES[$fieldname]['size'] > get_max_upload_file_size($CFG->maxbytes))) {
// oversize file will be ignored, error added to array to notify
// web service client
+ $file->errortype = 'fileoversized';
$file->error = get_string('maxbytes', 'error');
} else {
$file->filepath = $_FILES[$fieldname]['tmp_name'];
@@ -129,12 +130,9 @@
$existingfile = $fs->file_exists($file_record->contextid, $file_record->component, $file_record->filearea,
$file_record->itemid, $file_record->filepath, $file_record->filename);
if ($existingfile) {
- //if allow automatic rename (avoid)
- $fileerror = new stdClass();
- $fileerror->filename = $file->filename;
- $fileerror->errortype = 'filenameexist';
- $fileerror->errormsg = get_string('filenameexist', 'webservice', $file->filename);
- $results[] = $fileerror;
+ $file->errortype = 'filenameexist';
+ $file->error = get_string('filenameexist', 'webservice', $file->filename);
+ $results[] = $file;
} else {
$stored_file = $fs->create_file_from_pathname($file_record, $file->filepath);
$results[] = $file_record;

0 comments on commit 3b40f3b

Please sign in to comment.
Something went wrong with that request. Please try again.