MDL-22634 fixed exception when adding files with the same name via file browser

This commit is contained in:
Petr Skoda
2010-06-01 08:18:25 +00:00
parent fd17ce0fb7
commit fccd424e2e
+7 -2
View File
@@ -344,6 +344,8 @@ class file_info_stored extends file_info {
return null;
}
$fs = get_file_storage();
$now = time();
$newrecord = new object();
@@ -353,13 +355,16 @@ class file_info_stored extends file_info {
$newrecord->filepath = $this->lf->get_filepath();
$newrecord->filename = $newfilename;
if ($fs->file_exists($newrecord->contextid, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename)) {
// file already exists, sorry
return null;
}
$newrecord->timecreated = $now;
$newrecord->timemodified = $now;
$newrecord->mimetype = mimeinfo('type', $newfilename);
$newrecord->userid = $userid;
$fs = get_file_storage();
if ($file = $fs->create_file_from_pathname($newrecord, $pathname)) {
return $this->browser->get_file_info($this->context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
}