Sergej Fomin
Sergej Fomin

Reputation: 1992

Laravel show images outside root folder

I am running a Laravel website on local machine. my laravel is in folder: /Username/bigproject/laravel-project

In the views of my Laravel app there are tags which should show files from /Username/bigproject/images folder (so it's outiside laravel root folder). How can I form the url in the src so this images are displayed?

<img src="/Username/bigproject/images/image1.jpg"> doesn't work, of course.

I've played with disks storages from https://laravel.com/docs/5.4/filesystem but had no results.

PS. This project is actually for local use only.

Upvotes: 1

Views: 3005

Answers (3)

nirmeets
nirmeets

Reputation: 33

If project is for local use only and assuming image are in server root or any folder inside server root (like htdocs, html, public_html, etc) the best option would be to form img tag like

src="127.0.0.1/bigproject/images/image1.jpg"

If files are outside the webroot / servers root you can access them like

file:///c:/Users/Bigproject/images/image1.jpg

Upvotes: 0

user10226920
user10226920

Reputation:

As the web server cant access files out side of its root, you can create a symbolic link so the files can be in two locations at once.

ln -s /Username/bigproject/images /Username/bigproject/larave-project/public 

thus allowing the web-server (ultimately the browser) to use the access the files with <img src="/catPic.jpg">

Upvotes: 2

brnd0
brnd0

Reputation: 442

From top of my head so I might be missing something:

  • cd to myApp/storage
  • run ln -s /home/me/documents/myFolder myfolder to create symlink

In /config/filesystems.php add to 'disks' array:

'mydisk' => 
  [
    'driver' => 'local',
    'root' => storage_path('storage/myfolder'),
    'url' => env('APP_URL').'/myfolder'
  ]

Please let me know if it works or not (was not tested), or correct for typos.

Upvotes: 0

Related Questions