亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel獲取圖像的文件內容但不適用于生產環境

Laravel獲取圖像的文件內容但不適用于生產環境

呼啦一陣風 2022-01-07 14:22:15
我的代碼在 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 環境中運行。任何想法都會幫助我。謝謝
查看完整描述

2 回答

?
翻翻過去那場雪

TA貢獻2065條經驗 獲得超14個贊

只需ob_get_clean();在響應文件之前添加。

它將清理所有緩沖區并返回內容以顯示圖像。

查看完整回答
反對 回復 2022-01-07
?
海綿寶寶撒

TA貢獻1809條經驗 獲得超8個贊

如果命令ob_get_clean();對您有幫助,請在__<?php .


查看完整回答
反對 回復 2022-01-07
  • 2 回答
  • 0 關注
  • 179 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號