0

sorry but I would need help with a project and I would be really grateful if you would help me. The problem is that i cannot view the images from public/storage in a blade page. To display the images I wrote:

<img class="card-img-top" src="{{ asset('storage/images/' . $category->image) }}" alt="">

To create the folder public/storage I used the command:

php artisan storage:link

image of folder path

I tried to delete and to recreate the folder but it still doesn't work

The path of images:

storage/app/public/images/

image of folder path

I'm so sorry for my english, I hope you understand the problem.

Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
  • can you show the exact path of the images uploaded in storage folder – John Lobo Jun 14 '21 at 16:26
  • 1
    I edit the post, hope that's what you were asking. Again sorry, it's my first question in stackoverflow – Jose Sgariglia Jun 14 '21 at 16:43
  • path is proper.are you sure $category->image has value .for testing purpose hardcode path instead od dynamic once – John Lobo Jun 14 '21 at 16:43
  • print $category->image too for testing purpose. and try accessing image directly from browser – John Lobo Jun 14 '21 at 16:44
  • yes before I tested and the value is correct. The problem is that i can't access in the storage folder – Jose Sgariglia Jun 14 '21 at 16:46
  • yes i got it but your code and folder looks good.any way once you delete shortcut created storage folder from public/ and run php artisan stoage:link again – John Lobo Jun 14 '21 at 16:47
  • the problem persists, in any case thanks for the help – Jose Sgariglia Jun 14 '21 at 16:53
  • strange issue .if you are in linux check once permission .since both storage and code looks good,what error you get when you accessing directly from browser .try accessing one image in browser yourdomain/storage/images/1623598728.jpg – John Lobo Jun 14 '21 at 16:55
  • for the permission, I just checked and everything seems normal. For the error in the browser, don't show any error. It just doesn't show the picture. Now i'm checking in 'yourdomain/storage/images/1623598728.jpg' and get errore 404 – Jose Sgariglia Jun 14 '21 at 16:59
  • okay.will see some other might help on that.without project debugging bit diffcult for me so. – John Lobo Jun 14 '21 at 17:02

1 Answers1

0

If you are a Linux user, then sometimes you need to give permission additionally to make it accessible. If you create your storage folder by the command php artisan storage:link and the storage folder has been corrupted, then delete the generated folder from public on the root and generate the shortcut by running the command again. Hopefully it will work.

S Ahmed Naim
  • 315
  • 1
  • 8
  • It is strongly advised never to use 777 as folder permissions for security reasons. – Luckyfella Jun 14 '21 at 18:51
  • Yeah, i agree with your point. It might be done only for testing purpose on local server. Thank you so much. – S Ahmed Naim Jun 14 '21 at 18:56
  • I tried to generate the folder from root but don't work. – Jose Sgariglia Jun 14 '21 at 20:51
  • @SAhmedNaim it was a good suggestion to check folder permissions though! Found a more detailed post about this: https://stackoverflow.com/questions/30639174/how-to-set-up-file-permissions-for-laravel/37266353#37266353 - 755 for folders seems to be a good starting point. I guess it depends a bit on server configuration finally – Luckyfella Jun 14 '21 at 21:38
  • @JoseSgariglia If you don't have `root` permission then add `sudo` on linux machine before running the artisan command. If the problem still exists, then please write in details about your problem. – S Ahmed Naim Jun 15 '21 at 05:50
  • The problem is when i want show the image from storage folder, it doesn't appear. I tried to write all path of image (without use any value) but still don't working. I tested and the problem is that i can't access in the storage folder, i don't why. The code seems correct. The static images on other folder in `public` show without problem – Jose Sgariglia Jun 15 '21 at 10:14
  • I think a solution, that is to create a function that move the image from the `public/storage/image` to `public/foldername` but also do it, i have the error that the path is incorrect. – Jose Sgariglia Jun 15 '21 at 10:17