/** * @test */ public function overrideFileNameShouldOverrideFileName() { $path = ROOT_TESTS . '/data/self-lussing-manatee.jpg'; $upload = new FileUpload($path); $upload->setOverrideFilename('tussin-lussu.luz'); $this->assertEquals('tussin-lussu.luz', $upload->getUploadFilename()); $upload->setOverrideBasename('luudendorf'); $this->assertEquals('luudendorf.luz', $upload->getUploadFilename()); }
/** * @param FileUploadEvent $event */ public function beforeUpload(FileUploadEvent $event) { if (!$this->belongsToProfile($event->getProfile()->getIdentifier())) { return; } $upload = $event->getFileUpload(); if (!preg_match("/^image/", $upload->getMimeType())) { return; } $helper = new ImageMagickHelper($upload->getRealPath(), $this->tempFiles, $this->commandDefinitions); $tempnam = $helper->execute(); $pinfo = pathinfo($upload->getUploadFilename()); $nupload = new FileUpload($tempnam); $mimeTypes = new MimeTypes(); $extension = $mimeTypes->mimeTypeToExtension($nupload->getMimeType()); $nupload->setOverrideFilename($pinfo['filename'] . '.' . $extension); $event->setFileUpload($nupload); }
/** * @param File $file * @param FileUpload $upload * @return Resource */ public function findResourceForUpload(File $file, FileUpload $upload) { $file = clone $file; $hash = sha1_file($upload->getRealPath()); $profileObj = $this->profiles->getProfile($file->getProfile()); $finder = new ResourceFinder(array('hash' => $hash)); $resources = $this->backend->findByFinder($finder); if ($resources) { foreach ($resources as $resource) { if (!$resource->isExclusive()) { $file->setResource($resource); if (!$profileObj->isSharedResourceAllowed($file)) { $file->unsetResource(); } break; } } } if (!$file->getResource()) { $resource = Resource::create(); $resource->setDateCreated(new DateTime()); $resource->setHash($hash); $resource->setSize($upload->getSize()); $resource->setMimetype($upload->getMimeType()); $file->setResource($resource); if (!$profileObj->isSharedResourceAllowed($file)) { $resource->setExclusive(true); } $this->create($resource, $upload->getRealPath()); $file->setResource($resource); } return $file->getResource(); }