예제 #1
0
 private function createDownloadResponse($stream, $filename)
 {
     $response = new StreamedResponse(function () use($stream) {
         stream_copy_to_stream($stream, fopen('php://output', 'w'));
     });
     $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, Transliterator::transliterate($filename));
     $response->headers->set('Content-Disposition', $disposition);
     $response->headers->set('Content-Type', 'application/octet-stream');
     return $response;
 }
예제 #2
0
 /**
  * {@inheritDoc}
  */
 public function name($object, PropertyMapping $mapping)
 {
     $file = $mapping->getFile($object);
     $name = $file->getClientOriginalName();
     if ($this->transliterate) {
         $name = Transliterator::transliterate($name);
     }
     /** @var $file UploadedFile */
     return uniqid() . '_' . $name;
 }
예제 #3
0
 /**
  * @inheritDoc
  */
 public function name($object, PropertyMapping $mapping)
 {
     if (empty($this->propertyPath)) {
         throw new \LogicException('The property to use can not be determined. Did you call the configure() method?');
     }
     $file = $mapping->getFile($object);
     try {
         $name = $this->getPropertyValue($object, $this->propertyPath);
     } catch (NoSuchPropertyException $e) {
         throw new NameGenerationException(sprintf('File name could not be generated: property %s does not exist.', $this->propertyPath), $e->getCode(), $e);
     }
     if (empty($name)) {
         throw new NameGenerationException(sprintf('File name could not be generated: property %s is empty.', $this->propertyPath));
     }
     if ($this->transliterate) {
         $name = Transliterator::transliterate($name);
     }
     // append the file extension if there is one
     if ($extension = $this->getExtension($file)) {
         $name = sprintf('%s.%s', $name, $extension);
     }
     return $name;
 }