Intervention/imageで本番環境でだけファイル保存不可

Can't write image data to path (/work/storage/app/public

のようなエラーが出る場合。

どうやら環境によっては、直接保存できいないらしい。

大丈夫な例

保存するときはStorage::putを使う。

use Illuminate\Support\Facades\Storage;

//中略

$img = Image::make($request->file)->resize(300, 300, function ($constraint) {
    $constraint->aspectRatio();
})->stream('jpg', 100);

Storage::put('/public/icon/'. $fileName.'.jpg', $img);

ダメな例

$img = Image::make($request->file)->resize(300, 300, function ($constraint) {
      $constraint->aspectRatio();
  })->stream('jpg', 100);

  Storage::put('/public/icon/'. $fileName.'.jpg', $img);//直接保存はできないことがある

LaravelでIntervention/image で圧縮した画像をファイルに保存せずにバイナリで取得する方法

Intervention Image | Intervention Image v2 | intervention.io

無制限に質問可能なプログラミングスクール!

万が一転職できない場合は、転職保障全額返金できるコースもあり!!

無制限のメンター質問対応

 

DMMウェブキャンプでプログラミングを学習しませんか?

独学より成長スピードをブーストさせましょう!

 

まずは無料相談から!

おすすめの記事