コード例 #1
0
ファイル: ImageInfo.php プロジェクト: knodejs/ckfinder_gulp
 public function execute(Request $request, WorkingFolder $workingFolder, Config $config, CacheManager $cache)
 {
     $fileName = (string) $request->get('fileName');
     if (null === $fileName || !File::isValidName($fileName, $config->get('disallowUnsafeCharacters'))) {
         throw new InvalidRequestException('Invalid file name');
     }
     if (!Image::isSupportedExtension(pathinfo($fileName, PATHINFO_EXTENSION))) {
         throw new InvalidNameException('Invalid source file name');
     }
     if (!$workingFolder->containsFile($fileName)) {
         throw new FileNotFoundException();
     }
     $cachePath = Path::combine($workingFolder->getResourceType()->getName(), $workingFolder->getClientCurrentFolder(), $fileName);
     $imageInfo = array();
     $cachedInfo = $cache->get($cachePath);
     if ($cachedInfo && isset($cachedInfo['width']) && isset($cachedInfo['height'])) {
         $imageInfo = $cachedInfo;
     } else {
         $file = new DownloadedFile($fileName, $this->app);
         if ($file->isValid()) {
             $image = Image::create($file->getContents());
             $imageInfo = $image->getInfo();
             $cache->set($cachePath, $imageInfo);
         }
     }
     return $imageInfo;
 }
コード例 #2
0
ファイル: CopiedFile.php プロジェクト: vobinh/PHP
 /**
  * Returns target file name of the copied file
  *
  * @return string
  */
 public function getTargetFilename()
 {
     if ($this->targetFolder->containsFile($this->getFilename()) && strpos($this->copyOptions, 'overwrite') === false && strpos($this->copyOptions, 'autorename') !== false) {
         $this->autorename();
     }
     return $this->fileName;
 }
コード例 #3
0
 /**
  * Copies current file
  *
  * @param string $copyOptions defines copy options in case if file already exists
  *                            in target directory:
  *                            - autorename - renames current file (see File::autorename())
  *                            - overwrite - overwrites existing file
  *
  * @return bool true if file was copied successfully
  *
  * @throws \Exception
  */
 public function doCopy($copyOptions)
 {
     $originalFileStream = $this->getContentsStream();
     $originalFileName = $this->getFilename();
     // Don't copy file to itself
     if ($this->targetFolder->getBackend() === $this->resourceType->getBackend() && $this->targetFolder->getPath() === $this->getPath()) {
         $this->addError(Error::SOURCE_AND_TARGET_PATH_EQUAL);
         return false;
         // Check if file already exists in target backend dir
     } elseif ($this->targetFolder->containsFile($this->getFilename()) && strpos($copyOptions, 'overwrite') === false) {
         if (strpos($copyOptions, 'autorename') !== false) {
             $this->autorename();
         } else {
             $this->addError(Error::ALREADY_EXIST);
             return false;
         }
     }
     if ($this->targetFolder->putStream($this->getFilename(), $originalFileStream)) {
         $resizedImageRepository = $this->resourceType->getResizedImageRepository();
         $resizedImageRepository->copyResizedImages($this->resourceType, $this->folder, $originalFileName, $this->targetFolder->getResourceType(), $this->targetFolder->getClientCurrentFolder(), $this->getFilename());
         $this->getCache()->copy(Path::combine($this->resourceType->getName(), $this->folder, $originalFileName), Path::combine($this->targetFolder->getResourceType()->getName(), $this->targetFolder->getClientCurrentFolder(), $this->getFilename()));
         return true;
     } else {
         $this->addError(Error::ACCESS_DENIED);
         return false;
     }
 }
コード例 #4
0
 /**
  * Main command method.
  *
  * @param Request       $request       Current request object
  * @param WorkingFolder $workingFolder Current working folder object
  *
  * @return array
  *
  * @throws \Exception
  */
 public function execute(Request $request, WorkingFolder $workingFolder)
 {
     $fileName = $request->get('fileName');
     $backend = $workingFolder->getBackend();
     if (!$workingFolder->containsFile($fileName)) {
         throw new \Exception('File not found', Error::FILE_NOT_FOUND);
     }
     $fileMetadada = $backend->getMetadata(Path::combine($workingFolder->getPath(), $fileName));
     return $fileMetadada;
 }
コード例 #5
0
 public function isValid()
 {
     if (!$this->saveAsNew && !$this->exists()) {
         throw new FileNotFoundException();
     }
     if ($this->newFileName) {
         if (!File::isValidName($this->newFileName, $this->config->get('disallowUnsafeCharacters'))) {
             throw new InvalidNameException('Invalid file name');
         }
         if ($this->workingFolder->containsFile($this->newFileName)) {
             throw new AlreadyExistsException('File already exists');
         }
         if ($this->resourceType->getBackend()->isHiddenFile($this->newFileName)) {
             throw new InvalidRequestException('New provided file name is hidden');
         }
     }
     if (!$this->hasValidFilename() || !$this->hasValidPath()) {
         throw new InvalidRequestException('Invalid filename or path');
     }
     if ($this->isHidden() || $this->hasHiddenPath()) {
         throw new InvalidRequestException('Edited file is hidden');
     }
     return true;
 }
コード例 #6
0
ファイル: ImageResize.php プロジェクト: knodejs/ckfinder_gulp
 public function execute(Request $request, WorkingFolder $workingFolder, Config $config, ResizedImageRepository $resizedImageRepository)
 {
     $fileName = (string) $request->query->get('fileName');
     if (null === $fileName || !File::isValidName($fileName, $config->get('disallowUnsafeCharacters'))) {
         throw new InvalidRequestException('Invalid file name');
     }
     $ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
     if (!Image::isSupportedExtension($ext)) {
         throw new InvalidNameException('Invalid source file name');
     }
     if (!$workingFolder->containsFile($fileName)) {
         throw new FileNotFoundException();
     }
     list($requestedWidth, $requestedHeight) = Image::parseSize((string) $request->query->get('size'));
     $resizedImage = $resizedImageRepository->getResizedImage($workingFolder->getResourceType(), $workingFolder->getClientCurrentFolder(), $fileName, $requestedWidth, $requestedHeight);
     return array('url' => $resizedImage->getUrl());
 }
コード例 #7
0
ファイル: EditedFile.php プロジェクト: vobinh/PHP
 /**
  * Validates the file
  *
  * @return bool true if file passed the validation
  *
  * @throws AlreadyExistsException
  * @throws FileNotFoundException
  * @throws InvalidExtensionException
  * @throws InvalidNameException
  * @throws InvalidRequestException
  * @throws InvalidUploadException
  */
 public function isValid()
 {
     if ($this->newFileName) {
         if (!File::isValidName($this->newFileName, $this->config->get('disallowUnsafeCharacters'))) {
             throw new InvalidNameException('Invalid file name');
         }
         if ($this->resourceType->getBackend()->isHiddenFile($this->newFileName)) {
             throw new InvalidRequestException('New provided file name is hidden');
         }
         if (!$this->resourceType->isAllowedExtension($this->getNewExtension())) {
             throw new InvalidExtensionException();
         }
         if ($this->config->get('checkDoubleExtension') && !$this->areValidDoubleExtensions($this->newFileName)) {
             throw new InvalidExtensionException();
         }
         if ($this->workingFolder->containsFile($this->newFileName)) {
             throw new AlreadyExistsException('File already exists');
         }
     }
     if (!$this->hasValidFilename() || !$this->hasValidPath()) {
         throw new InvalidRequestException('Invalid filename or path');
     }
     if ($this->isHidden() || $this->hasHiddenPath()) {
         throw new InvalidRequestException('Edited file is hidden');
     }
     if ($this->config->get('checkDoubleExtension') && !$this->areValidDoubleExtensions()) {
         throw new InvalidExtensionException();
     }
     if (!$this->resourceType->isAllowedExtension($this->getExtension())) {
         throw new InvalidExtensionException();
     }
     if (!$this->saveAsNew && !$this->exists()) {
         throw new FileNotFoundException();
     }
     if ($this->newContents) {
         if (Utils::containsHtml(substr($this->newContents, 0, 1024)) && !in_array(strtolower($this->newFileName ? $this->getNewExtension() : $this->getExtension()), $this->config->get('htmlExtensions'))) {
             throw new InvalidUploadException('HTML detected in disallowed file type', Error::UPLOADED_WRONG_HTML_FILE);
         }
         $maxFileSize = $this->resourceType->getMaxSize();
         if ($maxFileSize && strlen($this->newContents) > $maxFileSize) {
             throw new InvalidUploadException('Uploaded file is too big', Error::UPLOADED_TOO_BIG);
         }
     }
     return true;
 }
コード例 #8
0
ファイル: Thumbnail.php プロジェクト: knodejs/ckfinder_gulp
 public function execute(Request $request, WorkingFolder $workingFolder, Config $config, ThumbnailRepository $thumbnailRepository)
 {
     if (!$config->get('thumbnails.enabled')) {
         throw new CKFinderException('Thumbnails feature is disabled', Error::THUMBNAILS_DISABLED);
     }
     $fileName = (string) $request->get('fileName');
     $ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
     if (!Image::isSupportedExtension($ext, $thumbnailRepository->isBitmapSupportEnabled())) {
         throw new InvalidNameException('Invalid source file name');
     }
     if (null === $fileName || !File::isValidName($fileName, $config->get('disallowUnsafeCharacters'))) {
         throw new InvalidRequestException('Invalid file name');
     }
     if (!$workingFolder->containsFile($fileName)) {
         throw new FileNotFoundException();
     }
     list($requestedWidth, $requestedHeight) = Image::parseSize((string) $request->get('size'));
     $thumbnail = $thumbnailRepository->getThumbnail($workingFolder->getResourceType(), $workingFolder->getClientCurrentFolder(), $fileName, $requestedWidth, $requestedHeight);
     Utils::removeSessionCacheHeaders();
     $response = new Response();
     $response->setPublic();
     $response->setEtag(dechex($thumbnail->getTimestamp()) . "-" . dechex($thumbnail->getSize()));
     $lastModificationDate = new \DateTime();
     $lastModificationDate->setTimestamp($thumbnail->getTimestamp());
     $response->setLastModified($lastModificationDate);
     if ($response->isNotModified($request)) {
         return $response;
     }
     $thumbnailsCacheExpires = (int) $config->get('cache.thumbnails');
     if ($thumbnailsCacheExpires > 0) {
         $response->setMaxAge($thumbnailsCacheExpires);
         $expireTime = new \DateTime();
         $expireTime->modify('+' . $thumbnailsCacheExpires . 'seconds');
         $response->setExpires($expireTime);
     }
     $response->headers->set('Content-Type', $thumbnail->getMimeType() . '; name="' . $thumbnail->getFileName() . '"');
     $response->setContent($thumbnail->getImageData());
     return $response;
 }
コード例 #9
0
 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));
 }
コード例 #10
0
ファイル: DownloadedFile.php プロジェクト: vobinh/PHP
 /**
  * Checks if file exists
  *
  * @return bool true if file exists
  */
 public function exists()
 {
     return $this->workingFolder->containsFile($this->fileName);
 }
コード例 #11
0
ファイル: Proxy.php プロジェクト: knodejs/ckfinder_gulp
 public function execute(Request $request, WorkingFolder $workingFolder, EventDispatcher $dispatcher, Config $config)
 {
     $fileName = (string) $request->query->get('fileName');
     $thumbnailFileName = (string) $request->query->get('thumbnail');
     if (!File::isValidName($fileName, $config->get('disallowUnsafeCharacters'))) {
         throw new InvalidRequestException(sprintf('Invalid file name: %s', $fileName));
     }
     $cacheLifetime = (int) $request->query->get('cache');
     if (!$workingFolder->containsFile($fileName)) {
         throw new FileNotFoundException();
     }
     if ($thumbnailFileName) {
         if (!File::isValidName($thumbnailFileName, $config->get('disallowUnsafeCharacters'))) {
             throw new InvalidRequestException(sprintf('Invalid resized image file name: %s', $fileName));
         }
         if (!$workingFolder->getResourceType()->isAllowedExtension(pathinfo($thumbnailFileName, PATHINFO_EXTENSION))) {
             throw new InvalidExtensionException();
         }
         $resizedImageRespository = $this->app->getResizedImageRepository();
         $file = $resizedImageRespository->getExistingResizedImage($workingFolder->getResourceType(), $workingFolder->getClientCurrentFolder(), $fileName, $thumbnailFileName);
         $dataStream = $file->readStream();
     } else {
         $file = new DownloadedFile($fileName, $this->app);
         $file->isValid();
         $dataStream = $workingFolder->readStream($file->getFilename());
     }
     $proxyDownload = new ProxyDownloadEvent($this->app, $file);
     $dispatcher->dispatch(CKFinderEvent::PROXY_DOWNLOAD, $proxyDownload);
     if ($proxyDownload->isPropagationStopped()) {
         throw new AccessDeniedException();
     }
     $response = new StreamedResponse();
     $response->headers->set('Content-Type', $file->getMimeType());
     $response->headers->set('Content-Length', $file->getSize());
     $response->headers->set('Content-Disposition', 'inline; filename="' . $fileName . '"');
     if ($cacheLifetime > 0) {
         Utils::removeSessionCacheHeaders();
         $response->setPublic();
         $response->setEtag(dechex($file->getTimestamp()) . "-" . dechex($file->getSize()));
         $lastModificationDate = new \DateTime();
         $lastModificationDate->setTimestamp($file->getTimestamp());
         $response->setLastModified($lastModificationDate);
         if ($response->isNotModified($request)) {
             return $response;
         }
         $response->setMaxAge($cacheLifetime);
         $expireTime = new \DateTime();
         $expireTime->modify('+' . $cacheLifetime . 'seconds');
         $response->setExpires($expireTime);
     }
     $chunkSize = 1024 * 100;
     $response->setCallback(function () use($dataStream, $chunkSize) {
         if ($dataStream === false) {
             return false;
         }
         while (!feof($dataStream)) {
             echo fread($dataStream, $chunkSize);
             flush();
             @set_time_limit(8);
         }
         return true;
     });
     return $response;
 }