/** * Copies a file (no persistence). * * @param File $resource * * @return File */ private function copy(File $resource, ResourceNode $destParent) { $ds = DIRECTORY_SEPARATOR; $workspace = $destParent->getWorkspace(); $newFile = new File(); $newFile->setSize($resource->getSize()); $newFile->setName($resource->getName()); $newFile->setMimeType($resource->getMimeType()); $hashName = 'WORKSPACE_' . $workspace->getId() . $ds . $this->container->get('claroline.utilities.misc')->generateGuid() . '.' . pathinfo($resource->getHashName(), PATHINFO_EXTENSION); $newFile->setHashName($hashName); $filePath = $this->container->getParameter('claroline.param.files_directory') . $ds . $resource->getHashName(); $newPath = $this->container->getParameter('claroline.param.files_directory') . $ds . $hashName; $workspaceDir = $this->filesDir . $ds . 'WORKSPACE_' . $workspace->getId(); if (!is_dir($workspaceDir)) { mkdir($workspaceDir); } copy($filePath, $newPath); return $newFile; }
public function deleteContent(File $file) { $ds = DIRECTORY_SEPARATOR; $uploadFile = $this->fileDir . $ds . $file->getHashName(); @unlink($uploadFile); }
private function returnFile(File $file) { // see https://github.com/claroline/CoreBundle/commit/7cee6de85bbc9448f86eb98af2abb1cb072c7b6b $this->get('session')->save(); $path = $this->fileDir . DIRECTORY_SEPARATOR . $file->getHashName(); $response = new BinaryFileResponse($path); return $response; }