Skip to content

Commit

Permalink
MDL-30496 fix upload max size issue when server limit is set + return…
Browse files Browse the repository at this point in the history
… some kind of json error object for filenameexists and oversizedfile errors
  • Loading branch information
mouneyrac authored and Aparup Banerjee committed Dec 1, 2011
1 parent 6416c6c commit 3b40f3b
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions webservice/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3b40f3b

Please sign in to comment.