I am trying to upload and retrieve image in my Laravel project. It worked perfectly in my local server, but after uploading in live server, its not working.
I am using nginx.
I have tried php artisan storage:link
but it says
The "public/storage" directory already exists
I am using this line to open the stored image in a new page.
<a href="{{ url('/storage/images/'.$file->file_name) }}" title="">View</a>
If I place mouse on the view button, it shows this link: my_ip/storage/images/image.png
which I think is correct.
However, clicking the link redirects to homepage.
If you are still stuck on this question, this is what worked for me:
In my case I had to change the APP_URL in .env file to the name of my site. It was defaulted to http://localhost. Once I change it everything worked perfectly.
The href
will be correct, but that's not the issue. The issue is the presence of the file at the location of the link. It's not there, as you're finding.
When you upload, make sure you are not uploading a real directory at public/storage
.
On your local server, did you, by mistake, create a real directory at public/storage
?
If you did, you need to know that the laravel convention is to store your files in the storage/app/public
directory in your app directory.
You don't create the folder public/storage
yourself.
You create a symlink to link it to there instead. That way, stuff you put in storage/app/public
, also appears, because of the symlink, at public/storage
.
First check your local server follows the laravel convention outlined above (and in the docs), then, after uploading to your server, try the storage:link
command again, and, so long as you don't have a real directory at public/storage
anymore, but just a link, it should hopefully work.
Note what I've done here is interpret the error message you were getting about that directory already existing.
Also, check this answer if you are using Homestead. Instead of creating a storage link on the host computer, you should ssh into Vagrant and create a storage link here.
In case you have uploaded public/storage folder to server and getting error: The "public/storage" directory already exists.
just delete it with
rm -R public/storage
and run the command again
php artisan storage:link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With