2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

laravelでstorage配下の画像をシンボリックリンクを張らずに表示する方法

Posted at

###/storage/app/images/の画像を表示してみる

フロント側(bladeファイル)

<img src="/get_request_image?name=test.png">

こんな感じで。
ディレクトリまで動的にする場合は、ディレクトリ名も渡してあげます。

//bladeファイル
<img src="/get_request_image?filename=dir_name01&name=test.png">

とりあえずルーティング書きます。

//web.php
Route::get('/get_request_image', 'TestController@get_request_image');
//TestController.php
public function get_request_image(Request $request){
        $data = $request->all();
        $path = storage_path("app/images/" . $data["file_name"]);
        return Response()->file($path);
    }

画像名を渡したらpathを返します。

images/配下も動的にしたい場合はディレクトリ名も受け取ります。

public function get_request_image(Request $request){
        $data = $request->all();
        $path = storage_path("app/images/" . $data["dir_name"] . $data["file_name"]);
        return Response()->file($path);
    }

こんな感じでどうでしょう。

2
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?