Can you try removing your public/storage directory and try running storage:link again? Is it possible that the public/storage directory already existed before?
Symlink not working on windows
Hello,
My symlink does not work out correctly. I already type: php artisan storage:link
As I place an image in storage/app/public/slides/random-image.jpeg , my public/storage folder remains empty.
Any clue why?
@rfountain Old is gold. That worked for me.
Probably permissions for the public/storage folder that do now allow for files to be created in the directory
Windows does not have symlinks. They have something similar. I suggest you use a virtual machine running a linux distribution (Ubuntu, CentOs or similar) to host your site. Then you will have a environment that is quite close to the production environment.
Here is a guide for Ubuntu
https://www.howtoforge.com/tutorial/ubuntu-laravel-php-nginx/
Can you run php artisan storage:link ? Will it works on Windows?
I don't like using virtual machine to code. I normally code my laravel projects on Windows localhost and they work just fine.
I already checked the public/storage/slides permission. It is write permissable.
Is reading the the public/storage folder is requirements for storage? Can you not read it directly from the storage/app/public/slides folder?
They work just fine until they don't :)
are you working just for yourself, meaning only local projects or do you ever deploy your projects on a production server for other people to use them?
The advice above is great if you deploy your projects as most of the servers are unix based, so having same environment benefits you 100% of the time.
If you still want to run on Windows, take a look at this answer on how to create the symlink
https://github.com/laravel/framework/issues/15439#issuecomment-408036822
I successfully created the symlink. Yet, when I upload a new image and delete the old one, the new image is not mirror to the public/storage and the old still remains. I thought it would be a complete mirror of storage/app/public folder?
Is creating the public/storage directory necessary seems, I can still read the image directly from the storage/app folder and it works!
As I said above, if you are using the projects only for local development, then do it however it works 😁
it won't work once you deploy on a server. But you don't want to have a production like environment anyway, so again, do whatever it works for you.
We are here to give an advice, not to convince you to do it the proper way.
Thanks for advice, I would like it to work even after I upload it to the server.
And I still have this problem: when I upload a new image and delete the old one, the new image is not mirror to the public/storage and the old still remains. I thought it would be a complete mirror of storage/app/public folder?
Is the command that I write in gitbash works just like in Linux environment?
The public/storage is a mirror of storage/app/public not vice versa. So it depends on how and where do you delete the image from. Showing code is always better then theory.
Also when you say you delete it, can you still see the image on a page, even after you delete it, or you just see it in the system?
PageController.php
public function store_home_slides(Request $request)
{
...
$slides = HomeSlidesModel::find($id);
$file = $request->file('slides');
if($file)
{
//storage/app
Storage::delete($slides->image);
//storage/app/slides/random.jpeg
$path = $request->file('slides')->store('public/slides');
Log::info('path :'.$path);
Session::flash('flash', 'Successfully save data');
}
$slides->title = $request->title;
$slides->image = $path;
$slides->update();
This is my delete code and how I save the path to the database.
When I deleted the image, it means I delete the old image and create the new one. To be accurate, this is an edit image feature.
@davy_yg my other question was how do you know that the delete works at all? Is it deleted from one place only and still shows in the other folder?? Is the image still visible on the page after it is being deleted??
Not having your environment nor your code it is hard to predict or tell what is going on, you need to debug yourself..
The delete does works since it only delete from my storage/app/public folder. The new image also appears in this folder after I uploaded the new image. Yet, it still remains in public/storage folder.
I basically only need the logic or the algorithm.
Do I have to delete and upload the image in both folders? Since the image only mirror after I type this command:
Admin@LAPTOP-HTFI5LEL MINGW64 /d/xampp72/htdocs/aws_admin_test
ln -sr storage/app/public public/storage
Yet, it is not continously mirror.
You should delete from one place only, the storage folder. Now why the symlink does not work on Windows I really don't know. You can google that I guess.
Check this guide out on how to create symlinks on Windows.
https://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/
But then again I highly suggest you get an *nix machine to develop on since 99% (maybe a bit exagerated) of the tutorials are done on *nix system and yes the system Jeffrey is using is a *nix based system.
D:\xampp72\htdocs\aws_admin_test>mklink /J storage/app/public public/storage Invalid switch - "app".
I am not familiar with linux. Is this not possible in Windows?
Check this tutorial: https://github.com/laravel/framework/issues/15439
Any clue what the last comment means?
type: "nfs"
mount_opts: ['nolock,vers=3,udp,noatime,actimeo=1']
D:\xampp72\htdocs\aws_admin_test>mklink /J public\storage storage\app\public
Hey, it finally works!
php artisan storage:link
I just have to check the public/storage file from explorer not through sublime. My sublime does not show what is inside the storage symlink folder.
The problem is when using windows
solution:
In my case, I am using laragon.
LINK CREATION (This is because the php artisan storage: link does not work on windows)
- For this case, you will have access to images
- Open cmd as administrator
- Verify that public access does not work (public \ images)
- Then copy: mklink / J C: \ laragon \ www \ project-name \ public \ images C: \ laragon \ www \ project-name \ storage \ app \ images
This would be similar to: php artisan storage: link
Take into account that to save in images it must be configured in the filesytem file (conf / filesytem)
'links' => [ public_path ('storage') => storage_path ('app / public'), public_path ('images') => storage_path ('app / images'), ],
@davy_yg hello, I am facing same problem on windows. Can you tell me details about that solution ? please
You probably created the symlinks in Linux and then copied the files to Windows. I had the same problem! The solution was to delete the symlinks created in Linux (in my case, created in the docker) and then run the "php artisan storage:link" command to recreate the Windows symlinks.
Please or to participate in this conversation.