Permalink
Browse files

Merge branch 'm20_MDL-25215_filepicker_saveas' of git://github.com/do…

…ngsheng/moodle
  • Loading branch information...
2 parents cbe4cbc + 7d2882c commit 419814db024fbf88f03c33ed4c75c48c3bb64781 @skodak skodak committed Feb 14, 2011
Showing with 15 additions and 1 deletion.
  1. +15 −1 repository/upload/lib.php
View
16 repository/upload/lib.php
@@ -105,7 +105,21 @@ public function upload($saveas_filename, $maxbytes) {
if (empty($saveas_filename)) {
$record->filename = clean_param($_FILES[$elname]['name'], PARAM_FILE);
} else {
- $record->filename = $saveas_filename;
+ $ext = '';
+ $match = array();
+ $filename = clean_param($_FILES[$elname]['name'], PARAM_FILE);
+ if (preg_match('/\.([a-z0-9]+)$/i', $filename, $match)) {
+ if (isset($match[1])) {
+ $ext = $match[1];
+ }
+ }
+ $ext = !empty($ext) ? $ext : '';
+ if (preg_match('#\.(' . $ext . ')$#', $saveas_filename)) {
+ // saveas filename contains file extension already
+ $record->filename = $saveas_filename;
+ } else {
+ $record->filename = $saveas_filename . '.' . $ext;
+ }
}
if ($this->mimetypes != '*') {

0 comments on commit 419814d

Please sign in to comment.