Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Neeraj1005's avatar

how to show an image which is stored in outside public folder

I am not getting an image. I have used these two methods but not get any output. Basically I have stored my image outer of a public folder. can anyone help me out of this problem?

<img src="{{asset('uploads/logo/'.$flogo['image'])}}"> 

OR

          <img src="/uploads/logo/{{$flogo['image']}}">
0 likes
14 replies
Sinnbeck's avatar

What is the path of the image on the disk (from laravel root)?

Snapey's avatar

If you want the image available to the outside world, it must be in the public folder, or in a folder that has a symlink to public

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

I would really recommend that you use the storage directory and symlink it (look at the link posted earlier). Using a custom directory like that is possible but goes against how laravel was designed

If you avosolutely have to use a custom directory like that, you can either symlink it into the public directory, or create a controller for the route, that gets the raw file content and serves it back in the response

1 like
Neeraj1005's avatar

@sinnbeck So, basically I have to stored all images in a public directory or storage directory rather than a custom directory. This is my store image code, so can you please suggest me where I have to change the code and how to pass it into images directory.

         if ($request->hasFile('image')) {
            if ($request->file('image')->isValid()) {
                
                $fileName=$request->file('image')->getClientOriginalName();
                $fileName =time()."_".$fileName;
                //upload
                $request->file('image')->move('uploads/logo', $fileName);
                    
                    //column name 
                $records['image']=$fileName;
                
            }
        }
Sinnbeck's avatar

Static images that you use (logo and such) should go in public directly.

Assets from your users should go in storage/app/public (you can add /uploads to that if you want), which is then symlinked to public

To change your code just do this (or use the helpers on the Storage::disk('public') facade.

$request->file('image')->move(storage_path('app/public/uploads/logo'), $fileName);

It is then available at http://yourdomain.com/storage/uploads/logo/filename.jpg

Neeraj1005's avatar

@sinnbeck Now I have my custom create uploads move inside the public folder and currently it is running okk. but I have one confusion regarding the public and storage folder?

$request->file('image')->move(storage_path('app/public/uploads/logo'), $fileName);

using this line of code it creates a folder uploads/logo inside public folder. Is it a good idea to create an image structure inside the public folder either we have to change the code and store images in storage folder and get image using symlink? plz, tell me if you have time for this...?

Sinnbeck's avatar

If they are all public then it should not be an issue. Just be sure that they get a random name to that no two names are the same. Users will need to know the exact file name to get acces to it.

Is there some reason that people can only view their own images? If so I can give you another solution perhaps :)

Neeraj1005's avatar

@sinnbeck Basically there is no reason that people can only view their own images. All images are stored inside the public folder. but inside the public folder file stored with their original name. I just want to know that is there any security issueto store images in the public or storage folder? And in this code, if I want to store imge inside storage folder, How can I do this?

Controller code
$request->file('image')->move(storage_path('uploads/logo'), $fileName);

blade code
<td> <img src="{{url('uploads/logo/'.$item->image)}}" width="50" class="img-thumbnail thumbnail-2"></td>
Sinnbeck's avatar

There should not be as long as you make sure to validate the image properly (dont let users upload a php file or the link)

The blade needs the storage directory

<img src="{{url('storage/uploads/logo/'.$item->image)}}" width="50" class="img-thumbnail thumbnail-2"></td>
saber13812002's avatar

in my case, my file name has "+" in it. like "Frame+2856.png" and laravel didn't show me the image

I was forced to rename it.

this is the strangest thing that I have seen in laravel

JussiMannisto's avatar

@saber13812002 It's a web thing, not a Laravel thing. Plus sign is often used to represent the space character in URLs. If the filename can contain special characters, you should encode it in the URL.

But I'd avoid using special characters in filenames altogether. And never use original filenames sent by the client.

Please or to participate in this conversation.