/** * Moves a file from given filepath to directory for original images for album * * If an item is given, UID of item is used as filename for item in original items directory * * @param string $filePath Full qualified filepath of file to move * @param Tx_Yag_Domain_Model_Item $item Item that should hold file (not modified, make sure to set sourceuri manually! * @return string * @throws Exception */ protected function moveFileToOrigsDirectory($filePath, Tx_Yag_Domain_Model_Item $item = null) { // Create path to move file to $origsFilePath = $this->fileManager->getOrigFileDirectoryPathForAlbum($this->album); $fileSuffix = pathinfo($filePath, PATHINFO_EXTENSION); if ($item !== null) { if ($item->getOriginalFilename()) { $origsFilePath .= $item->getUid() . '_' . $this->fileSystemDiv->cleanFileName($item->getOriginalFilename()); } else { $origsFilePath .= $item->getUid() . '.' . $fileSuffix; // if we get an item, we use UID of item as a part of the filename } } else { $origsFilePath .= Tx_Yag_Domain_FileSystem_Div::getFilenameFromFilePath($filePath); // if we do not get one, we use filename of given filepart } if (!rename($filePath, $origsFilePath)) { throw new Exception('Could not move file ' . $filePath . ' to ' . $origsFilePath, 1294176900); } // Set appropriate file mask $this->setFileMask($origsFilePath); return $origsFilePath; }
protected function buildItemObjectInfo(PathInfo $pathInfo, \Tx_Yag_Domain_Model_Item $item) { return array('size' => $item->getFilesize(), 'atime' => $item->getTstamp()->getTimestamp(), 'mtime' => $item->getTstamp()->getTimestamp(), 'ctime' => $item->getCrdate()->getTimestamp(), 'mimetype' => 'image/jpeg', 'yagItem' => $item, 'name' => $item->getOriginalFilename(), 'identifier' => \Tx_Yag_Domain_FileSystem_Div::concatenatePaths(array($pathInfo->getAlbumPath(), $item->getTitle() . ' |' . $item->getUid())), 'storage' => $this->storage->getUid(), 'description' => $item->getDescription(), 'title' => $item->getTitle(), 'height' => $item->getHeight(), 'width' => $item->getWidth(), 'sourceUri' => $item->getSourceuri()); }
/** * Sends an item as download. The fileHash (or at least a part of 5 characters) is used to avoid grabbing the whole * database by incrementing the itemUid. * * @param Tx_Yag_Domain_Model_Item $item * @param string $fileHash */ public function downloadAction(Tx_Yag_Domain_Model_Item $item, $fileHash) { $requestedFileName = Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($item->getSourceuri()); $hashLength = strlen($fileHash) > 5 ? 5 : strlen($fileHash); if ($fileHash == '' || $fileHash !== substr($item->getFilehash(), 0, $hashLength) || !is_readable($requestedFileName)) { $this->flashMessageContainer->add('The requested file was not found.', 'File not found', FlashMessage::ERROR); $this->forward('index', 'Error'); } $this->response->setHeader('Cache-control', 'public', true); $this->response->setHeader('Content-Description', 'File transfer', true); $this->response->setHeader('Content-Disposition', 'attachment; filename="' . $item->getOriginalFilename() . '"', true); $this->response->setHeader('Content-Type', $item->getItemType(), true); $this->response->setHeader('Content-Transfer-Encoding', 'binary', true); $this->response->sendHeaders(); @readfile($requestedFileName); exit; }