【问题标题】:Image source not readable, with Laravel 8图像源不可读,使用 Laravel 8
【发布时间】:2021-06-14 00:12:49
【问题描述】:

我在尝试添加新图像时遇到了这个问题,我使用干预包将图像调整到固定大小。这是我的功能:

我已将enctype="multipart/form-data" 添加到create.blade

【问题讨论】:

  • 请务必粘贴您的代码。
  • 请从 $imagePath 中删除 store 方法。

标签: laravel image intervention


【解决方案1】:

我认为这可能会解决您的问题。

public function store(Request $request)
{
  $data = $request->validate([
    'caption'   => 'required',
    'image'     => 'required|image|mimes:jpeg,jpg,png,'
  ]);
  $file = $request->file('image');
  $filename = uniqid().substr(time(),0,6).".".$file->getClientOriginalExtension();
  if( !Storage::disk('public')->exists('posts') )
  {
      Storage::disk('public')->makeDirectory('posts');
  }
  Image::make($file)->resize(1200, 1200)->save('storage/posts/'.$filename);
  $data['image'] = $filename;
  auth()->user()->posts()->create($data);
  return redirect('/profile/'.auth()->user()->id);
}

  • 不要忘记导入use Illuminate\Support\Facades\Storage;use Intervention\Image\Facades\Image;

【讨论】:

  • 非常感谢,添加的图像有效,但不幸的是,图片出现在页面上就像没有读取mmm一样粘贴,那是没有图像出现,只是一个图片图标......这个是我的表演功能: public function show(AppPost $post) { $image = Image::make(public_path(storage_path("storage/{$post->image}")))->fit(500,500);返回视图('posts.show',紧凑('post')); }
  • 您没有将 $image 变量传递给视图。但是有一个问题,Image::make()->fit()返回这个类Intervention\Image\Facades\Image的实例。所以它不是图像。您可以在 img src 中回显图像文件夹名和文件名,然后使用 css 将其设为 500 * 500
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-22
  • 2016-12-19
  • 2018-05-05
  • 1970-01-01
  • 1970-01-01
  • 2017-06-09
相关资源
最近更新 更多