Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-30459 better error message when file already exist

  • Loading branch information...
commit f25aee3251b6a55547c5c4da7fa2d0567540b62b 1 parent a5b5881
@mouneyrac mouneyrac authored
Showing with 18 additions and 1 deletion.
  1. +1 −0  lang/en/webservice.php
  2. +17 −1 webservice/upload.php
View
1  lang/en/webservice.php
@@ -91,6 +91,7 @@
$string['externalservices'] = 'External services';
$string['externalserviceusers'] = 'External service users';
$string['failedtolog'] = 'Failed to log';
+$string['filenameexist'] = 'File name already exists: {$a}';
$string['function'] = 'Function';
$string['functions'] = 'Functions';
$string['generalstructure'] = 'General structure';
View
18 webservice/upload.php
@@ -15,7 +15,14 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * Accpet uploading files by web service token
+ * Accept uploading files by web service token
+ *
+ * POST params:
+ * token => the web service user token (needed for authentication)
+ * filepath => the private file aera path (where files will be stored)
+ * [_FILES] => for example you can send the files with <input type=file>,
+ * or with curl magic: 'file_1' => '@/path/to/file', or ...
+ *
* @package moodlecore
* @subpackage files
* @copyright 2011 Dongsheng Cai <dongsheng@moodle.com>
@@ -117,6 +124,15 @@
$file_record->license = $CFG->sitedefaultlicense;
$file_record->author = fullname($authenticationinfo['user']);;
$file_record->source = '';
+
+ //Check if the file already exist
+ $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)
+ throw new moodle_exception('filenameexist', 'webservice', '', $file->filename);
+ }
+
$stored_file = $fs->create_file_from_pathname($file_record, $file->filepath);
$results[] = $file_record;
}
Please sign in to comment.
Something went wrong with that request. Please try again.