diff --git a/h5p-default-storage.class.php b/h5p-default-storage.class.php index 1c564ad..f78b829 100644 --- a/h5p-default-storage.class.php +++ b/h5p-default-storage.class.php @@ -257,6 +257,26 @@ class H5PDefaultStorage implements \H5PFileStorage { return file_get_contents($this->path . $file_path); } + /** + * Save files uploaded through the editor. + * The files must be marked as temporary until the content form is saved. + * + * @param \H5peditorFile $file + * @param int $contentid + */ + public function saveFile($file, $contentId) { + $path = $this->path . '/' . ($contentId === 0 ? 'editor' : 'content') . '/' . $file->getType() . 's/' . $file->getName(); + self::dirReady($path); + + $fileData = $file->getData(); + if ($fileData) { + file_put_contents($path, $fileData); + } + else { + copy($_FILES['file']['tmp_name'], $path); + } + } + /** * Recursive function for copying directories. * diff --git a/h5p-file-storage.interface.php b/h5p-file-storage.interface.php index b75625e..9f44f94 100644 --- a/h5p-file-storage.interface.php +++ b/h5p-file-storage.interface.php @@ -125,4 +125,13 @@ interface H5PFileStorage { * @return string contents */ public function getContent($file_path); + + /** + * Save files uploaded through the editor. + * The files must be marked as temporary until the content form is saved. + * + * @param \H5peditorFile $file + * @param int $contentid + */ + public function saveFile($file, $contentId); }