/** * Save files uploaded through the editor. * * @param \H5peditorFile $file * @param int $contentid * @param \stdClass $context Course Context ID */ public function saveFile($file, $contentid, $contextid = null) { if ($contentid !== 0) { // Grab cm context $cm = \get_coursemodule_from_instance('hvp', $contentid); $context = \context_module::instance($cm->id); $contextid = $context->id; } // Files not yet related to any activities are stored in a course context // (These are temporary files and should not be part of backups.) $record = array('contextid' => $contextid, 'component' => 'mod_hvp', 'filearea' => $contentid === 0 ? 'editor' : 'content', 'itemid' => $contentid, 'filepath' => '/' . $file->getType() . 's/', 'filename' => $file->getName()); $fs = get_file_storage(); $filedata = $file->getData(); if ($filedata) { $stored_file = $fs->create_file_from_string($record, $filedata); } else { $stored_file = $fs->create_file_from_pathname($record, $_FILES['file']['tmp_name']); } return $stored_file->get_id(); }