3

I'm using storage_path() for storing uploaded images, but when I use it is pointing wrong on my page.

I use it like this {{ $data->thumbnail }} where $data came from the database and thumbnail comes as the string which used storage_path

Bryan P
  • 3,934
  • 5
  • 37
  • 57

2 Answers2

5

The storage_path function returns the path to the storage folder, which is inside the app folder --and outside the public folder-- so it's not directly accessible from the client, that's why your images are not being displayed. You can move them to the public folder path, or you could use a custom controller to handle the image requests, read the image from the storage folder and return the value.

5

Let us take a look at the default L4 application structure:

app // contains restricted server-side application data

app/storage // a writeable directory used by L4 and custom functions to store data ( i.e. log files, ... )

public // this directory is accessible for clients

If I were you, I would upload the file to the public directory directly:

  1. Store image here: public_path() . 'img/filename.jpg'
  2. Save the 'img/filename.jpg' in database
  3. Generate the image URL with url('img/filename.jpg') => http://www.your-domain.com/img/filename.jpg

Hope this helps.

Remluben
  • 1,245
  • 2
  • 14
  • 19