beli0135's avatar

Storage folder problem with slashes (Windows local)

Hi

I have a problem that I do not know how to resolve. Running Wamp64 on windows. Image is stored in storage/app/uploads whatever...

However, this code: {{ storage_path('app/').$post->image_path }}

gives me error as it cannot find image: D:\wamp64\www\lounginator\storage\app/uploads/imagename.jpg

Image was added by ->store method to "uploads" dir so it made app/uploads dir and stored file there

of course it can't as slashes are mixed with backslashes. If I upload it to linux server, all works, of course.

How to overcome this? (to work both in my local and in host server)

0 likes
6 replies
newbie360's avatar

@beli0135

<a href="/storage/app/uploads/imagename.jpg">image</a>

<a href="{{ url('storage/app/uploads/imagename.jpg') }}">image</a>
1 like
beli0135's avatar
{{ url('public/storage/app/'.$post->image_path)  }}

This worked, but I did have to put "public" in. Thank you. Is there something more elegant? public_path will also give me windows' path.

MichalOravec's avatar
Level 75

It should be

<img src="{{ asset("storage/{$post->image_path}") }}" alt="Image">

so withut public in the path.

1 like
beli0135's avatar

Link looks good this time. However, it doesn't want to display image. I guess it is another problem. I think I am getting 404

this is absolute path: (D:.....\my_project\storage\app\public\uploads

is there some permission to be added or?

newbie360's avatar

@beli0135

the command php artisan storage:link is point the public Disk

http://your-domain/storage

equal to

D:.....\my_project\public\storage

and hard linked  to

D:.....\my_project\storage\app\public

so if the image stored at D:.....\my_project\storage\app\public\uploads\test.jpg

the url is http://your-domain/storage/uploads/test.jpg

the URI part of the URL is /storage/uploads/test.jpg

1 like
beli0135's avatar

I know what happened, had problem with PHP yesterday, I lost storage link and composer is not working properly. Will fix this.

Thanks everyone, I learnt how to overcome the problem.

Please or to participate in this conversation.