/** * Creates a new file in the directory * * data is a readable stream resource * * @param string $name Name of the file * @param resource $data Initial payload * @return void */ public function createFile($name, $data = null) { \GO::debug("FSD::createFile({$name})"); $folder = $this->_getFolder(); if (!$folder->checkPermissionLevel(\GO\Base\Model\Acl::WRITE_PERMISSION)) { throw new Sabre\DAV\Exception\Forbidden(); } $newFile = new \GO\Base\Fs\File($this->path . '/' . $name); if ($newFile->exists()) { throw new \Exception("File already exists!"); } $tmpFile = \GO\Base\Fs\File::tempFile(); $tmpFile->putContents($data); if (!\GO\Files\Model\File::checkQuota($tmpFile->size())) { $tmpFile->delete(); throw new Sabre\DAV\Exception\InsufficientStorage(); } // $newFile->putContents($data); $tmpFile->move($folder->fsFolder, $name); $folder->addFile($name); }
/** * Add a filesystem file to this folder. The file will be moved to this folder * and added to the database. * * @param \GO\Base\Fs\File $file * @param boolean $appendNumberToNameIfExists Set if a number needs to be added to the name if the file already exists. * @return File */ public function addFilesystemFile(\GO\Base\Fs\File $file, $appendNumberToNameIfExists = false) { if (!File::checkQuota($file->size())) { throw new \GO\Base\Exception\InsufficientDiskspace(); } $file->move($this->fsFolder, false, false, $appendNumberToNameIfExists); $file->setDefaultPermissions(); return $this->addFile($file->name()); }