首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Intervention\Image\Exception\NotReadableException i

Intervention\Image\Exception\NotReadableException i
EN

Stack Overflow用户
提问于 2021-01-13 19:01:33
回答 1查看 244关注 0票数 0

在干预中,图像源在laravel 8中不可读。我已经尝试检查path是否存在,它确实存在,并尝试重新安装干预,但对laravel仍然不起作用。

代码语言:javascript
复制
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;
use Intervention\Image\ImageManager;

class PostsController extends Controller
{

  public function __construct()
  {
    $this->middleware('auth');
  }
  public function create()
  {
    return view('posts.create');
  }
  public function store()
  {
    $data  = request()->validate([
        // 'another' => '',
        'caption' => 'required',
        'image' => ['required', 'image'],
    ]);

    // open an image file
    $image = Image::make(public_path('storage/{$imagePath}'))->fit(1200, 1200);
    $image->save();
    $imagePath = request('image')->store('uploads', 'public');

    auth()->user()->posts()->create([
      'caption' => $data['caption'],
      'image' => $imagePath,
    ]);

    return redirect('/profile/' . auth()->user()->id);
  }
}

我不知道是不是public_path或者是什么导致了这里的错误!

EN

回答 1

Stack Overflow用户

发布于 2021-01-26 12:08:29

我尝试了下面的方法,它起作用了。

代码语言:javascript
复制
public function store()
{
    $data = request()->validate([
        'caption' => 'required',
        'image' => ['required', 'image'],
    ]);

    
    $imagePath = request('image')->store('uploads','public');
    //dd($imagePath);

    $img = ImageManagerStatic::make(storage_path().'/app/public/'.$imagePath);
    $img ->fit(400,400);
    $img -> save(storage_path().'/app/public/'.$imagePath);

    
    return redirect('/profile/' . auth()->user()->id);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65700600

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档