mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-34107 Upload repository - do not add a dot to files without an extension
This commit is contained in:
parent
d71b79a406
commit
970f0c0a36
@ -155,17 +155,22 @@ class repository_upload extends repository {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user