Added func. for saving uploaded files

h5p/h5p-moodle-plugin#48
HFJ-1845
pull/22/head
Frode Petterson 2016-04-25 14:31:25 +02:00
parent 7b38c3571e
commit 325ea27562
2 changed files with 29 additions and 0 deletions

View File

@ -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.
*

View File

@ -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);
}