Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 404 error while viewing image saved in public directory of laravel project

I created Laravel project and able to make it work to get json output as well. However image link in json is not working.

https://android.factory2homes.com/ json: https://android.factory2homes.com/index.php/api/products

image link:https://android.factory2homes.com/index.php/public/12142.jpg

i tried creating symlink and copied same image in storage folder as well, but not able to make it work.

like image 212
chetan suri Avatar asked Sep 13 '25 22:09

chetan suri


2 Answers

The public folder in a Laravel project is basically the root folder that shows up on the website URL.

For security issues, you really don't want the users to have the ability to write anything directly on the public folder, because if you are not careful they could overwrite your php scripts and have them do whatever they want.

So generaly speaking you create a simlink inside the public folder to the storage folder that is outside the public directory. Laravel has even a built in artisan command to do that exactly which is:

php artisan storage:link

The URL to any image stored in that folder would be in your example:

https://android.factory2homes.com/storage/12142.jpg

You do not have to put any .php file, or public or anything else.

like image 84
Arturo Alvarado Avatar answered Sep 15 '25 10:09

Arturo Alvarado


if the image is inside public then I don't think you need to give the url like index.php/public/someimage.jpg you can just do www.yousiteurl.com/someinage.jpg

like image 29
krtrth bilory Avatar answered Sep 15 '25 11:09

krtrth bilory