/** * @see inc/PMF_Attachment/Filesystem/PMF_Attachment_Filesystem_Entry#copyTo($entry) */ public function copyTo($target) { $retval = false; if (is_string($target)) { $target = new PMF_Attachment_Filesystem_File_Vanilla($target, self::MODE_WRITE); } else { $target->setMode(self::MODE_WRITE); } if ($target->isOk()) { while (!$this->eof()) { $target->putChunk($this->getChunk()); } $retval = true; } return $retval; }
/** * Save current attachment to the appropriate storage. The * filepath given will be processed and moved to appropriate * location. * * @param string $filepath full path to the attachment file * @param string $filename filename to force * * @return boolean * * TODO rollback if something went wrong */ public function save($filepath, $filename = null) { $retval = false; if (file_exists($filepath)) { $this->realHash = md5_file($filepath); $this->filesize = filesize($filepath); $this->filename = null == $filename ? basename($filepath) : $filename; $this->saveMeta(); $targetFile = $this->buildFilePath(); if (null !== $this->id && $this->createSubDirs($targetFile)) { /** * Doing this check we're sure not to unnecessary * overwrite existing unencrypted file duplicates. */ if (!$this->linkedRecords()) { $source = new PMF_Attachment_Filesystem_File_Vanilla($filepath); $target = $this->getFile(PMF_Attachment_Filesystem_File::MODE_WRITE); $retval = $source->moveTo($target); } else { $retval = true; } if ($retval) { $this->postUpdateMeta(); } else { /** * File wasn't saved */ $this->delete(); $retval = false; } } } return $retval; }