Example #1
0
 public function execute(WorkingFolder $workingFolder, Request $request)
 {
     $fileName = (string) $request->get('fileName');
     $thumbnail = (string) $request->get('thumbnail');
     $fileNames = (array) $request->get('fileNames');
     if (!empty($fileNames)) {
         $urls = array();
         foreach ($fileNames as $fileName) {
             $urls[$fileName] = $workingFolder->getFileUrl($fileName);
         }
         return array('urls' => $urls);
     }
     return array('url' => $workingFolder->getFileUrl($fileName, $thumbnail));
 }
 public function execute(WorkingFolder $workingFolder, Request $request, Config $config)
 {
     $fileName = $request->get('fileName');
     $thumbnail = $request->get('thumbnail');
     $fileNames = (array) $request->get('fileNames');
     if (!empty($fileNames)) {
         $urls = array();
         foreach ($fileNames as $fileName) {
             if (!File::isValidName($fileName, $config->get('disallowUnsafeCharacters'))) {
                 throw new InvalidRequestException(sprintf('Invalid file name: %s', $fileName));
             }
             $urls[$fileName] = $workingFolder->getFileUrl($fileName);
         }
         return array('urls' => $urls);
     }
     if (!File::isValidName($fileName, $config->get('disallowUnsafeCharacters')) || $thumbnail && !File::isValidName($thumbnail, $config->get('disallowUnsafeCharacters'))) {
         throw new InvalidRequestException('Invalid file name');
     }
     if (!$workingFolder->containsFile($fileName)) {
         throw new FileNotFoundException();
     }
     return array('url' => $workingFolder->getFileUrl($thumbnail ? Path::combine(ResizedImage::DIR, $fileName, $thumbnail) : $fileName));
 }