/** * Get a stored_file instance by filename * * @param string $filename * @return \stored_file */ public function get($filename) { return $this->storage->get_file($this->context->id, self::COMPONENT, self::FILEAREA, self::ITEMID, self::FILEPATH, $filename); }
/** * Wrapper function useful for deleting an existing file (if present) just * before creating a new one. * * @param file_storage $fs File storage * @param array $filerecord File record in same format used to create file */ public static function delete_existing_file_record(file_storage $fs, array $filerecord) { if ($existing = $fs->get_file($filerecord['contextid'], $filerecord['component'], $filerecord['filearea'], $filerecord['itemid'], $filerecord['filepath'], $filerecord['filename'])) { $existing->delete(); } }