首页 > 解决方案 > 无法将图像数据写入路径 - 干预图像

问题描述

我正在尝试在我的 laravel 项目中使用干预包来调整图像的大小。我可以使用 Storage 门面存储图像,但是当我使用 Image 类存储它们时,它会引发以下错误。

无法将图像数据写入路径 (/var/www/commerce/storage/featureds/2-1537128615.jpg)

if ($request->has("featured_img")) {
    $file_path = $request->get("featured_img");
    $exp = explode("/",$file_path);
    $filename = $exp[1];
    $featured_path = "featureds/".$filename;
    \Storage::copy($request->get("featured_img"), $featured_path);

    \Image::make(\Storage::get($featured_path))->fit(400, 300)->save(storage_path($featured_path));
    $product->media()->where("type", "featured")->update(["path" => $featured_path]);

 }

我怎样才能解决这个问题 ?感谢您的所有帮助

标签: phplaravelintervention

解决方案


存储中有特色目录吗?

如果不是,则使用mkdir创建目录,因为 Intervention 不会自动创建目录。


推荐阅读