问题
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
回答1:
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:
- Store image here: public_path() . 'img/filename.jpg'
- Save the 'img/filename.jpg' in database
- Generate the image URL with url('img/filename.jpg') => http://www.your-domain.com/img/filename.jpg
Hope this helps.
回答2:
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.
来源:https://stackoverflow.com/questions/17029121/how-to-use-storage-path-to-view-an-image-in-laravel-4