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

This commit is contained in:
Davo Smith 2012-07-02 08:10:24 +01:00
parent d71b79a406
commit 970f0c0a36

View File

@ -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;
}
}
}