0

I have deployed a Laravel 8 application on my SiteGround website and have been trying to create a symbolic link in the public directory pointing to the storage/app/public directory using php artisan storage:link and I got the error, symlink(): no such file or directory in Filesystem.php. I have scoured the likes of stackoverflow and more for a few days to try and find an answer. The answer I found over and over again was https://stackoverflow.com/a/30198781/16932312 (using the AppServiceProvider.php way if that matters). However, when I changed my public path and printed it out to make sure it is correct I still got the error.

Eventually I decided to change the code that sets up the symbolic link from public_path(storage) => storage_path(app/public) to the hardcoded directories to see if that would work since the problem was that apparently one of the directories didn't exists. I called php artisan storage:link and lo and behold it worked! A symbolic link was created I didn't get an error!

Unfortunately though something is still not working I don't know if it's because I changed the way the symbolic link is set up or what but when I call Storage::url("imgs/image.jpg") or asset("storage/imgs/image.jpg") neither of them find the image. If it is the case on how I set up the symbolic link how do I solve this? Because my public path is pointing to the correct destination. It worked just fine right before I deployed it so I just don't know what could have caused it to stop working. Any help would be appreciated!

I don't know if these will help much but I printed out some values to check things:

<p>1) {{ public_path() }}</p>
<p>2) {{ storage_path() }}</p>
<p>3) {{ file_exists(public_path("storage")) }}</p>
<p>4) {{ file_exists(public_path("storage/imgs")) }}</p>
<p>5) {{ file_exists(public_path("storage/imgs/test.jpg")) }}</p>
<p>6) {{ file_exists(Storage::url("imgs/test.jpg")) }}</p>
<p>7) {{ file_exists(public_path("test")) }}</p>
<p>8) <img src="public_path('storage/imgs/test.jpg')" alt="Test"></p>

Both 1 and 2 print out the correct paths. 3, 4, and 5 print out 1. 6 and 7 print out nothing. Finally 8 just shows the alt with no image which I find strange because apparently that file exists.

Edit: I was just looking at it a little more and using Storage::url("imgs/test.jpg") or asset("storage/imgs/test.jpg") is actually giving me a 403 error when I'm trying to access it it looks like.

ParkMoss
  • 11
  • 6
  • 1
    Hey Park. A couple months ago I wrote [an article](https://kennyhorna.com/blog/file-storage-como-manejar-archivos-y-discos-en-laravel-0a85ea73-288d-4667-99f8-0f3d97c51a8d) about how the filesystem works in Laravel. It's in Spanish but you can easily translate it with Google. I hope it helps you :) – Kenny Horna Sep 17 '21 at 00:33

1 Answers1

0

In #8, you're using a helper function in your template but you shouldn't need it as /storage points to the right place. You should just be able to do:

<img src="/storage/imgs/test.jpg" alt="Test">
Drewster
  • 499
  • 5
  • 13
  • Yeah you're right. I think the actual problem now that I'm looking at more is the 403 I'm getting when trying to retrieve it from that link. I don't know if I should put that in a new question or just leave it in this one though. – ParkMoss Sep 17 '21 at 01:14
  • I think it's probably a new question. It could be the access to that file although I would have thought that would also turn up on the `file_exists()` then. – Drewster Sep 17 '21 at 01:20
  • Unless I misunderstand what you mean it does show up using file_exists() doesn't it? Looking at the answers I got back from my tests when I did `file_exists(public_path("storage/imgs/test.jpg"))` it showed up. – ParkMoss Sep 17 '21 at 01:32
  • That's what I meant. If you're getting the 403 from the , I'm surprised you can test for its existence. I was wondering if it's possible that the 403 is showing up from something else. – Drewster Sep 17 '21 at 01:40
  • If correct, please mark the answer as correct. :) – Drewster Sep 17 '21 at 02:19