1

I'm using Laravel 5.7. On my localhost, my storage works fine, and all images show as well, but on my host, new images don't display.

I use below code inisde the blade.php file:

{{ asset("storage/$slider") }} 

On my localhost it shows images:

localhost:8000/storage/sliders/HKeGwcvnXbjuiA6g9wsjnoqphJc5DGup78D92b4F.jpeg 

On my website I cannot access:

http://mywebsite.com/storage/sliders/HKeGwcvnXbjuiA6g9wsjnoqphJc5DGup78D92b4F.jpeg

8
  • why you cannot access it? Is there any error messages? Commented Dec 13, 2018 at 18:22
  • Unless there's a storage directory in the public folder, it's not directly accessible. You'll need to either create a storage folder in public, or find another way to serve the files. It could be accessible locally due to your site/folder structure. Commented Dec 13, 2018 at 18:22
  • @Smankusors it shows 404 page. Commented Dec 13, 2018 at 18:24
  • @aynbar there is a foder on my host and my images uploaded as well: storage/app/public/sliders Commented Dec 13, 2018 at 18:25
  • I'm using shared host. Commented Dec 13, 2018 at 18:26

1 Answer 1

1

now I use this route and It worked:

Route::get('storage/sliders/{filename}', function ($filename) { $path = storage_path('app/public/sliders/' . $filename); if (!File::exists($path)) { abort(404); } $file = File::get($path); $type = File::mimeType($path); $response = Response::make($file, 200); $response->header("Content-Type", $type); return $response; }); 

if you have another sub-directories you can use:

Route::get('storage/{path}/{filename}', function ($path,$filename) { $path = storage_path('app/public/'.$path.'/' . $filename); if (!File::exists($path)) { abort(404); } $file = File::get($path); $type = File::mimeType($path); $response = Response::make($file, 200); $response->header("Content-Type", $type); return $response; }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.