Ejemplo n.º 1
0
 /**
  * @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());
 }
Ejemplo n.º 2
0
 /**
  * @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);
 }