Esempio n. 1
0
 /**
  * Gets a thumbnail of the specified file
  *
  * @since API version 1.0
  *
  * @NoAdminRequired
  * @NoCSRFRequired
  *
  * @param int $x
  * @param int $y
  * @param string $file
  * @return JSONResponse|DownloadResponse
  */
 public function getThumbnail($x, $y, $file)
 {
     if ($x < 1 || $y < 1) {
         return new JSONResponse('Requested size must be numeric and a positive value.', Http::STATUS_BAD_REQUEST);
     }
     try {
         $preview = new Preview('', 'files', $file, $x, $y, true);
         echo $preview->showPreview('image/png');
         return new DownloadResponse($file . '.png', 'image/png');
     } catch (\Exception $e) {
         return new JSONResponse('File not found.', Http::STATUS_NOT_FOUND);
     }
 }
        foreach ($iter as $item) {
            if (is_file($item)) {
                $fileInfo = new SplFileInfo($item);
                // Is this an image ?
                $imgExt = strtolower($fileInfo->getExtension());
                if (in_array($imgExt, $fetchExt)) {
                    // get file name without $userDir
                    $shortFileName = substr($item, strlen($userDir));
                    // workaround for jpg == jpeg for showPreview method
                    if ($imgExt === 'jpg') {
                        $imgExt = 'jpeg';
                    }
                    // to check if preview exists on disk
                    $fileView = new \OC\Files\View('/' . $user . '/' . $currentDir);
                    $id = $fileView->getFileInfo($shortFileName)->getId();
                    // For each size
                    for ($x = 0; $x < $max_sf; $x++) {
                        // Generates missing thumbnails
                        if (!file_exists($datadir . '/' . $user . '/thumbnails/' . $id . '/' . $sizes[$x][0] . '-' . $sizes[$x][1] . '.png')) {
                            $preview = new Preview($user, $currentDir, $shortFileName, $sizes[$x][0], $sizes[$x][1], true);
                            $preview->showPreview('image/' . $imgExt);
                        }
                    }
                }
            }
        }
    }
}
?>