Ejemplo n.º 1
0
 /**
  * Checks if the current file has an extension allowed in its resource type.
  *
  * @return bool `true` if the file has an allowed exception.
  */
 public function hasAllowedExtension()
 {
     if (strpos($this->getFilename(), '.') === false) {
         return true;
     }
     $extension = $this->getExtension();
     return $this->resourceType->isAllowedExtension($extension);
 }
Ejemplo n.º 2
0
 /**
  * Returns URL to given file
  *
  * @param string      $fileName
  * @param string|null $thumbnailFileName
  *
  * @throws FileNotFoundException
  * @throws InvalidExtensionException
  * @throws InvalidRequestException
  *
  * @return null|string
  */
 public function getFileUrl($fileName, $thumbnailFileName = null)
 {
     $config = $this->app['config'];
     if (!File::isValidName($fileName, $config->get('disallowUnsafeCharacters'))) {
         throw new InvalidRequestException('Invalid file name');
     }
     if ($thumbnailFileName) {
         if (!File::isValidName($thumbnailFileName, $config->get('disallowUnsafeCharacters'))) {
             throw new InvalidRequestException('Invalid thumbnail file name');
         }
         if (!$this->resourceType->isAllowedExtension(pathinfo($thumbnailFileName, PATHINFO_EXTENSION))) {
             throw new InvalidExtensionException('Invalid thumbnail file name');
         }
     }
     if (!$this->containsFile($fileName)) {
         throw new FileNotFoundException();
     }
     return $this->backend->getFileUrl($this->resourceType, $this->getClientCurrentFolder(), $fileName, $thumbnailFileName);
 }
Ejemplo n.º 3
0
 /**
  * Replaces double extensions disallowed for the resource type.
  *
  * @param string       $fileName
  * @param ResourceType $resourceType
  *
  * @return string file name with replaced double extensions.
  */
 public static function replaceDisallowedExtensions($fileName, ResourceType $resourceType)
 {
     $pieces = explode('.', $fileName);
     $basename = array_shift($pieces);
     $lastExtension = array_pop($pieces);
     foreach ($pieces as $ext) {
         $basename .= $resourceType->isAllowedExtension($ext) ? '.' : '_';
         $basename .= $ext;
     }
     // Add the last extension to the final name.
     return $basename . '.' . $lastExtension;
 }