Silly mistakes you can make while uploading images or files in Laravel

There are many ways to upload files and images in Laravel. One of them is uploading the images/files to the storage folder. But the storage folder doesn’t really provide public access meaning it doesn’t give permission to view the files that are stored within the storage folder. For the users to be able to view them, we need to create a symlink. A symlink can be easily created using the terminal in localhost, however, it is a different story on the server where you may or may not have the necessary permissions to do so.

However, we are presenting the files to the public either way. So why not store them in the public folder itself. But here comes the twist. For this, I used the move() function. Gave the folder name parameter within the function and the folder was created on the public_html in server. But, the path that I perfectly provided in the img src gave only 404 File not found error. Took me hours to realize that public_html also doesn’t have the necessary permissions for the user to view it. So the files are not shown to the user. But then I moved all those files and folders within the public folder and voila, it worked.

To summarize the experience, Laravel has fixed folders that have enough permissions for the public to view. If you put your files in those folders, it is all good. But if you don’t then it’s ” Houston! we have a problem.” And it is better to upload files in public folder rather than storing on storage folder because you are uploading them for the public to view aren’t you?

Thank you for reading.

1 thought on “Silly mistakes you can make while uploading images or files in Laravel”

Leave a Comment

Your email address will not be published. Required fields are marked *

Tweet
Share
Share
Pin