我的代碼在 localhost 開發中工作<img class="img-fluid rounded-circle" src="{{ url('image?type=user&file='.Auth::user()->picture_file.'&mime='.Auth::user()->picture_mime) }}" alt="Image Description">將訪問imageController與get使用這個鏈接方法image?type=user&file=USER000053.png&mime=image/pngclass ImageController extends BaseController{ public function get(Request $request){ $file=Storage::disk($request->type)->get($request->file); return response($file,200)->header('content-Type',$request->mime); }}在我的filesystem.php配置文件下面'user' => [ 'driver' => 'local', 'root' => storage_path('app/user'), 'url' => env('APP_URL').'/storage', 'visibility' => 'public',],上面的代碼在本地主機上運行良好。但是當我們嘗試推送到生產服務器(centos os)時,該代碼將不起作用。它只是返回一個損壞圖像。我們已經嘗試過[檢查] 確保存儲和臨時可訪問。chmod 755. 即使我們嘗試過 777[檢查]chown到用戶 apache.apache[檢查] 設置 selinux 許可模式[檢查] 我們確保該文件已經存在$file_exists = Storage::disk($request->type)->exists($request->file);上面的代碼返回 true[檢查] 在下面嘗試此代碼$response = Response::make($file, 200);$response->header('Content-Type', $request->mime);return $response;還是不行試圖制作符號鏈接php artisan storage:link它在public文件夾上創建符號鏈接,但仍然無法正常工作嘗試下載但仍然無法正常工作 return response()->download(storage_path('app/' . $request->type . "/" . $request->file));我在 GCP 的 Centos 7 環境中運行。任何想法都會幫助我。謝謝
Laravel獲取圖像的文件內容但不適用于生產環境
呼啦一陣風
2022-01-07 14:22:15