4

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.

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I already ran simlink, but keep getting 404 error. I have to put /index.php after domain, then only Laravel is working.. I tried both links android.factory2homes.com/storage/12142.jpg & android.factory2homes.com/index.php/storage/12142.jpg... both gives 404 erroe
Having to include index.php means that you have some setup issue. For starter, when you include index.php you are calling to a script to be executed. You do not need to execute a script to get a file. Excecuting the script actually causes more things to fail when you are trying just to get a file. What webserver are you running? Laravel includes an .htaccess file that is in the public folder that apparently isn't being read or it's being ignored. You may also have file permission issues. The webserver may not have the proper rights to read the files you are trying to send.
Just try to put an image file in the public folder of android.factory2homes.com site. You should be able to retrieve that file with android.factory2homes.com/filename.jpg If you can't get that image file then: you either have file permission issues, or the server isn't setup properly, to which you should go to check the logs of the server to check what is going on. Also make 100% sure that the file you are trying to read (which I called filename.jpg) actually exists in that folder.
1

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

1 Comment

Laravel is storing images as index.php/public/someimage.jpg, currently trying to make images save to public_html and then retrieve in json, i was hoping laravel is able to make images readable in Public folder in Laravel project...
0

I resolved issue by savings images to Public_html folder instead of public folder in Laravel app root folder. Public_html is the path that is visible to public, hence other solutions weren't working.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.