getPath() public method

Example: getPath(45) => '/myImageFolder/Picture1.png'
public getPath ( integer | string $id ) : string
$id integer | string String for backward compatibility
return string
Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function move($pk, $targetPk, $position = 'first', $targetObjectKey = null, $overwrite = false)
 {
     if ($pk) {
         $path = $this->getPathFromPK($pk);
     } else {
         $path = '/';
     }
     $target = is_numeric($targetPk['id']) ? $this->webFilesystem->getPath($targetPk['id']) : $targetPk['id'];
     $target = $target . '/' . basename($path);
     if (!$overwrite && $this->webFilesystem->has($target)) {
         return ['targetExists' => true];
     }
     $this->checkAccess($path);
     $this->checkAccess($target);
     return $this->webFilesystem->move($path, $target);
 }
Exemplo n.º 2
0
 /**
  * @ApiDoc(
  *  section="File Manager",
  *  description="Displays a (complete) image (with cache-headers)"
  * )
  *
  * @Rest\QueryParam(name="path", requirements=".+", strict=true, description="The file path or its ID")
  *
  * @Rest\Get("/admin/file/image")
  *
  * @param ParamFetcher $paramFetcher
  * @return Response
  */
 public function showImageAction(ParamFetcher $paramFetcher)
 {
     $path = $paramFetcher->get('path');
     if (is_numeric($path)) {
         $path = $this->webFilesystem->getPath($path);
     }
     $this->checkAccess($path, ACL::MODE_VIEW);
     $file = $this->webFilesystem->getFile($path);
     if ($file->isDir()) {
         return;
     }
     $ifModifiedSince = $this->pageStack->getRequest()->headers->get('If-Modified-Since');
     if (isset($ifModifiedSince) && strtotime($ifModifiedSince) == $file->getModifiedTime()) {
         // Client's cache IS current, so we just respond '304 Not Modified'.
         $response = new Response();
         $response->setStatusCode(304);
         $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', $file->getModifiedTime()) . ' GMT');
         return $response;
     }
     $content = $this->webFilesystem->read($path);
     $image = \PHPImageWorkshop\ImageWorkshop::initFromString($content);
     $result = $image->getResult();
     $size = new FileSize();
     $size->setHandleFromBinary($content);
     $expires = 3600;
     //1 h
     $response = new Response();
     $response->headers->set('Content-Type', 'png' == $size->getType() ? 'image/png' : 'image/jpeg');
     $response->headers->set('Pragma', 'public');
     $response->headers->set('Cache-Control', 'max-age=' . $expires);
     $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', $file->getModifiedTime()) . ' GMT');
     $response->headers->set('Expires', gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
     ob_start();
     if ('png' === $size->getType()) {
         imagepng($result, null, 3);
     } else {
         imagejpeg($result, null, 100);
     }
     $response->setContent(ob_get_contents());
     ob_end_clean();
     return $response;
 }
Exemplo n.º 3
0
 /**
  * @param integer|string $id path or file id
  *
  * @return string
  */
 public function publicUrl($id)
 {
     return $this->webFilesystem->getPath($id);
 }