I am building an e-commerce application using Laravel framework. Which location is most suitable to upload product images, Slider images, Banner images and all dynamically uploaded images in frontend?
storage/app/public
public/img
If am going for storage/app/public location. How can I access those images to website frontend?
I really appreciate any help you can provide.
Store your images in your storage directory.
This is the best place as you can use the Storage facade which makes it easy to store images. https://laravel.com/docs/5.6/filesystem
You can also use the Storage facade the same way you would locally if you were to change your storage destination to a CDN (e.g. Amazon S3). You will just need to change the configuration in config/filesystems.php and the code to store the images will remain the same.
Once you do store the images in the storage directory you can expose them to the frontend by symlink-ing it using php artisan storage:link https://laravel.com/docs/5.6/filesystem#configuration
This will create a symlink from your storage directory in to the public directory.
You can use the helper asset to retrieve the path to the image. https://laravel.com/docs/5.6/helpers#method-asset
--
There are lots of examples on how to store files in the storage directory:
https://quickadminpanel.com/blog/file-upload-in-laravel-the-ultimate-guide/
https://scotch.io/tutorials/understanding-and-working-with-files-in-laravel
How to save uploaded image to Storage in laravel?
use
public/img
then locate it in the front end with asset function
{{ asset('name_of_file') }}
Related
I'm currently developing a social network using PHP Lumen (Like Laravel but without the frontend part), MySQL and Ionic framework.
What is the best approach to save user images in a way that only the user can get them?
I need to save a user profile picture, but I understand that saving the base64 format of the image in the database is not a good thing as the app scales.
So, my question is: should I save the image as it is but changing the name with some hash, as same as the folder so that only the user could get the right path to it and serve that path to the frontend?
Or, Is it posible to save the image into a folder that just the server can access, and just get the right url to the file using the user session token? Should I encrypt the images? Does it take too much time and processing?
First of all, you should not be using Lumen for building a social networking website. Where Lumen is lightweight, it is missing core utilities that Laravel offers.
Now getting back to your question, you will have to require league/flysystem in your project and use the storage API. You may have to deal with the configurations in Lumen in order to get the filesystem to work properly for you.
Just like Laravel, you should keep the storage folder out of the public folder and symlink the storage's public directory app's public directory. In Laravel, you have the php artisan storage:link command to achieve the results.
Now once the storage is properly configured, public files will be accessible directly when the directory is symlinked, and you can decide on the private files how should they be accessed. Flysystem provides you great flexibility on reading and writing content from/to the disk.
I created a video player project in laravel. the video will play from only authenticated users. using the inspect element if anyone gets a video link that is will not download from anyone.
video store location in storage/app/
The storage should not be available for clients accessing your server's files. They should only have access to the public folder. What I normally do is creating a route for accessing files in my storage folder. In this route you can check if you want to give access to the file.
Have also a look at https://laravel.com/docs/5.8/filesystem#downloading-files
I am trying to create a file manager or image storage app using php based framework codeigniter in which I want to create a feature to delete and restore images and folders.
So far i have developed every part of the app from upload to delete without the use of database but I could not find any way to restore back the images and folders to their original path.
I'm using PHP's rename() function to move the file to the deleted folder before deleting this permanently.
So is it possible to pass the original path info with the image or folder using metadata etc.?
I am new to web development and I have just deployed my site using Heroku. I am using Laravel as the framework and Postgres as the database.
In my site, I have a feature of storing images in my public/images folder. If I saved the images and changed the file permissions before deploying it on Heroku then the images are being displayed. However, if the images are uploaded directly through Heroku, the images won't be displayed.
I am guessing this is caused by file permissions. Maybe because the images that are being uploaded in the public/images folder in Heroku is not inheriting the permission of the folder?
The file system on Heroku is not persistent. You can't save files on the web server file system, and expect those files to be available for subsequent HTTP requests.
You need to use another persistence store, like storing those files on AWS S3 or in your database. There are also probably other addons that would allow you to save files simply enough.
Ref: https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem
Here's an example of saving and displaying images from a Postgresql database: Upload/Download file in POSTGRESQL database with PHP
Ive written a Laravel application where I upload images and pdf files.
Currently In uploading those into a folder within the public directory.
Now I been trying Envoyer.io, where I can easily deploy my projects to the server(s).
The problem here is that each project has its own directory. So everytime all those uploads dissapear.
Ive figgered out that Envoyer does use a symlink for the storage directory in every deployed project.
I can upload the files to the storage directory, but when I return the URL from the files in de storage pth I receive a path like "/var/www/project/app/storage/file.ext" which is the base path. I dont want to return those links in my API cause of security reasons. I there any way I can upload to the storage path and get those uploads with an more friendly URL? Or does anyone have an ither solution?
If you use Laravel Storage feature then you do not need to worry about absolute path. You can even save the files in amazon cloud on completely different machine.
Storage works only with file contents and relative paths instead of absolute paths like PHP File. However you cannot mix the Laravel Storage and PHP File logics easily.
Envoyer must keep the storage folder same within one application. If you need to share it with other projects then upload to Amazon or write your own implementation of the Storage Facade.
More info at http://laravel.com/docs/5.0/filesystem