【问题标题】:Can't write image data to path in laravel 8 using the Intervention library无法使用干预库将图像数据写入 laravel 8 中的路径
【发布时间】:2021-08-31 20:32:27
【问题描述】:

我正在使用 Laravel 8,但遇到了这个错误。

无法将图像数据写入路径(/home/u520518518/domains/dev.peacockindia.in/public_html/public/Backend/Image/Brand/2003012866_Brand-Image_Mobile_jpg)

这是我的代码

if($request->logo){
    $image = $request->file('logo');
    $img   = rand().'_'.'Brand-Image'.'_'.$request->title.'_'.$image->getClientOriginalExtension();
    $loc   = public_path('Backend/Image/Brand/'.$img);
    Image::make($image)->save($loc);
    $brand->logo   = $img;
}

【问题讨论】:

  • 看起来像权限问题,你有没有尝试写入存储
  • Image::make(storage_path().'/Backend/Image/Brand/'.$img)->save(public_path('Backend/Image/Brand/'.$img));

标签: php laravel


【解决方案1】:

我试过了

$loc   = 'Backend/Image/Brand/'.$img;

它的工作原理

【讨论】:

    【解决方案2】:
     $image = $request->file('image');
            $slug = Str::slug($request->name);
            if (isset($image))
            {
                $currentDate = Carbon::now()->toDateString();
                $imagename = $slug.'-'.$currentDate.'-'. uniqid() .'.'. $image->getClientOriginalExtension();
                if (!file_exists('storage/uploads/employee-images'))
                {
                    mkdir('storage/uploads/employee-images',0777,true);
                }
                $image->move('storage/uploads/employee-images',$imagename);
            }else{
                $imagename = "default.png";
            }
    

    【讨论】:

      猜你喜欢
      • 2014-10-19
      • 1970-01-01
      • 2016-01-15
      • 2017-01-25
      • 1970-01-01
      • 1970-01-01
      • 2019-02-25
      • 2015-09-23
      • 2020-03-29
      相关资源
      最近更新 更多