From ec8b711fb35026e33bdf6eed1b57f327fddebc2c Mon Sep 17 00:00:00 2001 From: skodak <skodak> Date: Sat, 6 Sep 2008 21:33:07 +0000 Subject: [PATCH] MDL-15919 do not modify $file_record parameters when creating new files --- lib/file/file_storage.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/file/file_storage.php b/lib/file/file_storage.php index 351278b959..631dd66390 100644 --- a/lib/file/file_storage.php +++ b/lib/file/file_storage.php @@ -360,7 +360,8 @@ class file_storage { $fid = $fid->get_id(); } - $file_record = (array)$file_record; // we support arrays too + $file_record = (array)$file_record; // we support arrays too, do not modify the submitted record! + unset($file_record['id']); unset($file_record['filesize']); unset($file_record['contenthash']); @@ -437,6 +438,8 @@ class file_storage { * @return object stored_file instance */ public function create_file_from_url($file_record, $url, $options=null) { + + $file_record = (array)$file_record; //do not modify the submitted record, this cast unlinks objects $file_record = (object)$file_record; // we support arrays too $headers = isset($options['headers']) ? $options['headers'] : null; @@ -469,6 +472,7 @@ class file_storage { public function create_file_from_pathname($file_record, $pathname) { global $DB; + $file_record = (array)$file_record; //do not modify the submitted record, this cast unlinks objects $file_record = (object)$file_record; // we support arrays too // validate all parameters, we do not want any rubbish stored in database, right? @@ -544,6 +548,7 @@ class file_storage { public function create_file_from_string($file_record, $content) { global $DB; + $file_record = (array)$file_record; //do not modify the submitted record, this cast unlinks objects $file_record = (object)$file_record; // we support arrays too // validate all parameters, we do not want any rubbish stored in database, right? -- 2.39.5