コード例 #1
0
 /**
  * Name a given file and return the name
  *
  * @param  FileInterface $file
  * @param Request $request The request object.
  * 
  * @return string
  */
 public function name(FileInterface $file, Request $request)
 {
     $subfolder = '';
     if ($subfolder = $request->get('subfolder')) {
         $subfolder .= '/';
     }
     return sprintf('%s.%s', $subfolder . uniqid(), $file->getExtension());
 }
コード例 #2
0
 protected function createSourceStream(FileInterface $file)
 {
     if ($file instanceof GaufretteFile) {
         // The file is always streamable as the chunk storage only allows
         // adapters that implement StreamFactory
         return $file->createStream();
     }
     return new LocalStream($file->getPathname());
 }
コード例 #3
0
 public function name(FileInterface $file)
 {
     $request = $this->container->get('request');
     $user = $this->container->get('security.context')->getToken()->getUser();
     if (!$user) {
         throw new AccessDeniedException('Not Logged In');
     }
     return sprintf('%s.%s', $user->getId() . "/" . uniqid(), $file->getExtension());
 }
コード例 #4
0
 public function upload(FileInterface $file, $name, $path = null)
 {
     $path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
     if ($file instanceof FlysystemFile) {
         if ($file->getFilesystem() == $this->filesystem) {
             $file->getFilesystem()->rename($file->getPath(), $path);
             return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
         }
     }
     $this->filesystem->put($name, file_get_contents($file));
     if ($file instanceof FlysystemFile) {
         $file->delete();
     } else {
         $filesystem = new LocalFilesystem();
         $filesystem->remove($file->getPathname());
     }
     return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
 }
コード例 #5
0
 public function upload(FileInterface $file, $name, $path = null)
 {
     $path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
     if ($file instanceof FlysystemFile) {
         if ($file->getFilesystem() == $this->filesystem) {
             $file->getFilesystem()->rename($file->getPath(), $path);
             return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
         }
     }
     $stream = fopen($file->getPathname(), 'r+');
     $this->filesystem->putStream($name, $stream);
     if (is_resource($stream)) {
         fclose($stream);
     }
     if ($file instanceof FlysystemFile) {
         $file->delete();
     } else {
         $filesystem = new LocalFilesystem();
         $filesystem->remove($file->getPathname());
     }
     return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
 }
コード例 #6
0
 public function upload(FileInterface $file, $name, $path = null)
 {
     $path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
     if ($this->filesystem->getAdapter() instanceof MetadataSupporter) {
         $this->filesystem->getAdapter()->setMetadata($name, array('contentType' => $file->getMimeType()));
     }
     if ($file instanceof GaufretteFile) {
         if ($file->getFilesystem() == $this->filesystem) {
             $file->getFilesystem()->rename($file->getKey(), $path);
             return new GaufretteFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
         }
     }
     $this->ensureRemotePathExists($path);
     $dst = $this->filesystem->createStream($path);
     $this->openStream($dst, 'w');
     $this->stream($file, $dst);
     if ($file instanceof GaufretteFile) {
         $file->delete();
     } else {
         $filesystem = new LocalFilesystem();
         $filesystem->remove($file->getPathname());
     }
     return new GaufretteFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
 }
コード例 #7
0
ファイル: UniqidNamer.php プロジェクト: beyzakokcan/ojs
 public function name(FileInterface $file)
 {
     $fileHelper = new FileHelper();
     $fileName = sprintf('%s.%s', uniqid(), $file->getExtension());
     return $fileHelper->generatePath($fileName, false) . $fileName;
 }
コード例 #8
0
 public function name(FileInterface $file)
 {
     return sprintf('%s.%s', uniqid(), $file->getExtension());
 }
コード例 #9
0
 /**
  * @inheritdoc
  */
 public function name(FileInterface $file)
 {
     $name = uniqid();
     return sprintf('%s/%s/%s.%s', substr($name, 0, 2), substr($name, 2, 2), $name, $file->getExtension());
 }