如何将Intervention流图像保存到Laravel的公共文件夹中

huangapple go评论61阅读模式
英文:

How to save image intervention stream image in public folder laravel

问题

我正在将图像文件保存在存储文件夹中,它运行正常

$ext = "jpg";
$imageConvert = \Image::make($image->getRealPath())->stream($ext, 60);
$img = rand(10, 100) . '_piku.' . $ext;
\Storage::put('public/piku/' . $img, $imageConvert);



但我想将图像存储在直接的 public/piku 文件夹中,而不是 storage/app/public/piku

那我应该如何做呢?

我尝试了所有这些:[点击这里](https://stackoverflow.com/questions/62377351/laravel-image-intervention-resize-and-put-in-storage)
但这些方法对于 intervention stream 的情况不起作用。
英文:

I'm saving image file in storage folder, its working fine

$ext = "jpg";
$imageConvert = \Image::make($image->getRealPath())->stream($ext, 60);
            $img = rand(10, 100) . '_piku.' . $ext;
            \Storage::put('public/piku/' . $img, $imageConvert);

But I want to store images in direct public/piku folder instead of storage/app/public/piku

So how can I do that?

I have tried all these: click here
But these methods not work for case of intervention stream.

答案1

得分: 1

尝试使用public_path函数:

public_path函数返回您的应用程序公共目录的完全限定路径。

$imageConvert->save(public_path('piku/' . $img));
英文:

try using public_path function:

The public_path function returns the fully qualified path to your application's public directory.

$imageConvert->save(public_path('piku/' . $img));

huangapple
  • 本文由 发表于 2023年7月6日 12:18:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76625463.html
  • image
  • intervention
  • laravel

如何在 :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定