Permalink
Browse files

MDL-34107 Upload repository - do not add a dot to files without an ex…

…tension
  • Loading branch information...
1 parent d71b79a commit 970f0c0a36314a90dfa57a89dc44979233b6ab21 @davosmith davosmith committed Jul 2, 2012
Showing with 14 additions and 9 deletions.
  1. +14 −9 repository/upload/lib.php
View
23 repository/upload/lib.php
@@ -155,17 +155,22 @@ public function process_upload($saveas_filename, $maxbytes, $types = '*', $savep
$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 . ')$#i', $saveas_filename)) {
- // saveas filename contains file extension already
+ if (strpos($filename, '.') === false) {
+ // File has no extension at all - do not add a dot.
$record->filename = $saveas_filename;
} else {
- $record->filename = $saveas_filename . '.' . $ext;
+ if (preg_match('/\.([a-z0-9]+)$/i', $filename, $match)) {
+ if (isset($match[1])) {
+ $ext = $match[1];
+ }
+ }
+ $ext = !empty($ext) ? $ext : '';
+ if (preg_match('#\.(' . $ext . ')$#i', $saveas_filename)) {
+ // saveas filename contains file extension already
+ $record->filename = $saveas_filename;
+ } else {
+ $record->filename = $saveas_filename . '.' . $ext;
+ }
}
}

0 comments on commit 970f0c0

Please sign in to comment.