简体   繁体   English

使用Apache使用Laravel后端查看图像

[英]Viewing Image with Laravel backend with Apache

I have images stored in my storage/app/images folder. 我的图像存储在我的storage / app / images文件夹中。

However, I cannot access or view any of these images on localhost without a 404 header. 但是,如果没有404标头,我无法在localhost上访问或查看任何这些图像。

I'm using Apache with the following htaccess to my Laravel REST API 我正在使用Apache将以下htaccess用于我的Laravel REST API

RewriteEngine On
RewriteBase /backendLaravel/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php [QSA,L]

I followed the php artisan storage:link that Laravel Docs provide, however nothing changes. 我遵循了php artisan storage:link Laravel Docs提供的php artisan storage:link ,但没有任何变化。

I want to be able to access these files publicly using http. 我希望能够使用http公开访问这些文件。 So, http://endpoint/SDUpload/hello.jpeg 所以, http://endpoint/SDUpload/hello.jpeg

How do I achieve this 我如何实现这一目标

storage:link creates a symbolic link from public/storage to storage/app/public . storage:link创建从public/storagestorage/app/public的符号链接。 Try either moving your storage/app/images folder to storage/app/public/images or create a symbolic link from public/storage/images to storage/app/images with: ln -s storage/app/images public/storage/images . 尝试将storage/app/images文件夹移动到storage/app/public/images或者使用以下命令创建从public/storage/imagesstorage/app/images的符号链接: ln -s storage/app/images public/storage/images

I haven't tried this but I'm assuming it would work. 我没试过这个,但我认为它会起作用。 In Laravel there is a public_path() helper as well as a storage_path() helper. 在Laravel中有一个public_path()帮助器以及一个storage_path()帮助器。 If you are trying to display these images online in your html, you can try to use the storage helper. 如果您尝试在html中在线显示这些图像,则可以尝试使用存储帮助程序。 Each of these helpers are used to access the given directory, either storage or public. 这些助手中的每一个都用于访问给定目录,存储或公共目录。

Example: 例:

<img src="{{ storage_path('app/images/image.jpg')">

Hope I could help. 希望我能提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM