【问题标题】:(Symfony 4) Liip/Imagine can't find my uploaded image(Symfony 4) Liip/Imagine 找不到我上传的图片
【发布时间】:2019-07-18 08:06:39
【问题描述】:

我将图像上传到我的 S3 服务器没有问题(所以我知道我的图像路径是合法的),但是当我尝试使用 Liip/Imagine 服务创建一些重新调整大小的图像时,Liip/Imagine 可以'找不到我上传的图片。

我将图像路径转储如下:

$idFile = $form['idFile']->getData();
dump($idFile);
die();

这是转储的样子:

ProfileController.php on line 340:
UploadedFile {#64 ▼
  -test: false
  -originalName: "file-name.png"
  -mimeType: "image/png"
  -error: 0
  path: "/tmp"
  filename: "php09sJr3"
  basename: "php09sJr3"
  pathname: "/tmp/php09sJr3"
  extension: ""
  realPath: "/tmp/php09sJr3"
  aTime: 2019-02-24 22:54:00
  mTime: 2019-02-24 22:54:00
  cTime: 2019-02-24 22:54:00
  inode: 12586620
  size: 97901
  perms: 0100600
  owner: 997
  group: 995
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
}

我知道这个路径 (/tmp/php09sJr3) 是合法的,因为我的文件都完美地上传到了我的 S3 存储桶,但是当我尝试在我的控制器中创建缩略图时:

public function saveProfileEditAction(Request $request, FilterService $imagine)
{
    $form = $this->createForm(UserProfileType::class, $user);
    $form->handleRequest($request);

    if($form->isSubmitted() && $form->isValid())        {
        $idFile = $form['idFile']->getData();

        if ($idFile != null){
            // this command right here 
            $resourcePath = $imagine->getUrlOfFilteredImage($idFile->getPathName(), 'my_thumb');

我收到以下错误:

Source image not resolvable "/tmp/php09sJr3" in root path(s) "/var/www/vhosts/mywebsite.com/public"

让这更令人困惑的是,当我检查时,/tmp/var/www/vhosts/mywebsite.com/public/tmp 中没有任何内容,但是我的文件仍然完美地上传到 S3。

这是我的配置 liip_imagine.yaml 文件:

liip_imagine :
    # configure resolvers
    resolvers :
        # setup the default resolver
        default :
            # use the default web path
            web_path : ~
    # your filter sets are defined here
    filter_sets :
        # use the default cache configuration
        cache : ~
        # the name of the "filter set"
        my_thumb :
            # adjust the image quality to 75%
            quality : 75
            # list of transformations to apply (the "filters")
            filters :
                # create a thumbnail: set size to 120x90 and use the "outbound" mode
                # to crop the image when the size ratio of the input differs
                thumbnail  : { size : [120, 90], mode : outbound }
                thumb_square :  { size : [300, 300], mode : outbound }
                thumb_rectangle_md : { size : [670, 400], mode : outbound }
                thumb_hd : { size : [1920, 1080], mode : outbound }
                # create a 2px black border: center the thumbnail on a black background
                # 4px larger to create a 2px border around the final image
                background : { size : [124, 94], position : center, color : '#000000' }

如何正确告诉 Liip/Imagine 我上传文件的文件路径?

【问题讨论】:

    标签: image file path upload


    【解决方案1】:

    你必须把它添加到你的 yaml 配置文件中(我的是 liip_imagine.yaml):

    loaders:
        default:
            filesystem:
                data_root: "/"
    

    所以在文件的范围内它看起来像:

    liip_imagine :
        # configure resolvers
        resolvers :
            # setup the default resolver
            default :
                # use the default web path
                web_path : ~
    # !!!!!!!!!!!!!!!!!!!!!START!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        loaders:
            default:
                filesystem:
                    data_root: "/"
    # !!!!!!!!!!!!!!!!!!!!!END!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    
        # your filter sets are defined here
        filter_sets :
            # use the default cache configuration
            cache : ~
            # the name of the "filter set"
            my_thumb :
                # adjust the image quality to 75%
                quality : 75
                # list of transformations to apply (the "filters")
                filters :
                    # create a thumbnail: set size to 120x90 and use the "outbound" mode
                    # to crop the image when the size ratio of the input differs
                    thumbnail  : { size : [120, 90], mode : outbound }
                    resize : { size : [670, 400], mode : outbound }
                    # create a 2px black border: center the thumbnail on a black background
                    # 4px larger to create a 2px border around the final image
                    background : { size : [124, 94], position : center, color : '#000000' }
    

    Liip 然后将创建缩略图、调整大小等...并将文件移动到:

    http://www.yourwebsite.com/media/cache/my_thumb/tmp/phpSQFUF1
    

    从技术上讲,在您的服务器中,它将是您根文件夹中的 /public/media/cache/my_thumb/tmp 文件夹。

    【讨论】:

      猜你喜欢
      • 2013-01-04
      • 2014-04-19
      • 2019-01-06
      • 2018-03-24
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2021-09-29
      • 1970-01-01
      相关资源
      最近更新 更多