gpt4 book ai didi

laravel - 不支持 Intervention\Image\Exception\NotSupportedException 编码格式 (tmp)

转载 作者:行者123 更新时间:2023-12-05 08:54:25 25 4
gpt4 key购买 nike

我在 Laravel 5.6 中使用 Intervention 包,每当我上传文件时都会遇到这个问题,我收到错误编码格式 (tmp) 不受支持。我也启用了 gdd2 扩展。这是我使用过的代码。

public function store(Request $request)
{
$this->validate($request , [
'name' => 'required|unique:categories',
'description' => 'max:355',
'image' => 'required|image|mimes:jpeg,bmp,png,jpg'
]);

// Get Form Image
$image = $request->file('image');
$slug = str_slug($request->name);
if (isset($image))
{
$currentDate = Carbon::now()->toDateString();
$imageName = $slug.'-'.$currentDate.'-'.uniqid().'.'.$image->getClientOriginalExtension();
// Check if Category Dir exists
if (!Storage::disk('public')->exists('category'))
{
Storage::disk('public')->makeDirectory('category');
}
// Resize image for category and upload
$categoryImage = Image::make($image)->resize(1600,479)->save();
Storage::disk('public')->put('category/'.$imageName, $categoryImage);

// Check if Category Slider Dir exists
if (!Storage::disk('public')->exists('category/slider'))
{
Storage::disk('public')->makeDirectory('category/slider');
}

// Resize image for category slider and upload
$categorySlider = Image::make($image)->resize(500,333)->save();
Storage::disk('public')->put('category/slider/'.$imageName, $categorySlider);

}
else
{
$imageName = 'default.png';
}

$category = new Category();
$category->name = $request->name;
$category->slug = $slug;
$category->description = $request->description;
$category->image = $imageName;

$category->save();
Toastr::success('Category Saved Successfully','Success');
return redirect()->route('admin.category.index');
}

最佳答案

您不需要在 Intervention\Image 类上使用 save() 函数,因为您正在通过 Storage Facade 将文件保存到公共(public)磁盘。

简单的替换行

$categoryImage = Image::make($image)->resize(1600,479)->save();

$categoryImage = Image::make($image)->resize(1600,479)->stream();

避免必须将图像存储到扩展名为 .tmp 的临时文件夹中。 Laravel Storage Facade 将处理由 Intervention\Image 创建的流并将文件存储到公共(public)磁盘。

关于laravel - 不支持 Intervention\Image\Exception\NotSupportedException 编码格式 (tmp),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50061985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com