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

DLUK44's avatar

File Uploads on Windows Server

Hi. I have a form that allows a user to upload an image. When a user submits the form, I store it using

$path = $request->file('image')->store('UploadedFiles')

In Windows, I can see the file is in

storage\app\UploadedFiles 

with a hashed name, and $path contains something like

UploadedFiles/AXF8JV8as4tdoOubZsVNnwAYvoZaZ73lfAPVf7jP.png

Something seems to have already gone wrong here as the Laravel documentation says "The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public." so why has my file ended up in

storage\app\UploadedFiles 

My question is, how do I display that image to the user as soon as they have submitted the form?

One way would be to copy or move the file to the public directory and then just use.

<img src='AXF8JV8as4tdoOubZsVNnwAYvoZaZ73lfAPVf7jP.png'>

but is this the correct or best way to do this?

I have read about

php artisan storage:link

and this seems to create a storage directory under /public. If I then get a directory listing of public it shows the newly created storage directory with a 'l' attribute to show that it is a link, so this process does seem to be working.

d----l       07/08/2020     12:35                storage

It is empty apart from a .gitignore file. I am confused about what this is meant to do, especially on Windows.

If I submit the form again after creating the storage:link, it doesn't seem to change the behaviour. The file still goes to

storage\app\UploadedFiles 

and the

public/storage

is empty.

If I store the file using

$path = $request->file('image')->store('public')

goes in to

storage\app\public

but it now also appears in

public\storage

I assume because of me running

php artisan storage:link

$path contains

public/cLjF6cyx6fzBzzltTFNI827KjGKUTMMNIPsd5QMB.png

I can now access the file from the browser by going to

<img src='storage/cLjF6cyx6fzBzzltTFNI827KjGKUTMMNIPsd5QMB.png'

but I am not sure I like that URL and this doesn't seem right to put every upload in the same folder.

So, should I just copy the file to /public each time or should I just always use store('public') and access it with the /storage/ URL or am I missing some Laravel magic that I should be taking advantage of?

Thanks. David.

0 likes
2 replies
jlrdw's avatar

You can have more than one folder to store images, sub folders.

Example"

storage\app\UploadedFiles\products
storage\app\UploadedFiles\some_other_image_folder
-------- etc

Do they need named like AXF8JV8as4tdoOubZsVNnwAYvoZaZ73lfAPVf7jP.png

Sometimes I name like:

ann478_127.jpg

Where 478 is count + 1 of images. and 127 is user id.

And a method I have only lets user 127 see their images.

MarianoMoreyra's avatar
Level 25

Hi @dluk44

You are not specifying the destination disk where you want to save the file, and the default disk is 'local'

config\filesystem.php

    /*
    |--------------------------------------------------------------------------
    | Default Filesystem Disk
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default filesystem disk that should be used
    | by the framework. The "local" disk, as well as a variety of cloud
    | based disks are available to your application. Just store away!
    |
    */

    'default' => env('FILESYSTEM_DRIVER', 'local'),

If you take a look below at the same file, you have a 'local' and a 'public' disk defined:

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

As you may see...it's the 'public' one that you want to use to have your image accesible to the web.

The store() method accepts the disk as a second parameter, so your code should be:

$path = $request->file('image')->store('UploadedFiles', 'public')

Then you'll be able to access those images at the view using

<img src='{{ asset('storage/cLjF6cyx6fzBzzltTFNI827KjGKUTMMNIPsd5QMB.png') }}'>

Hope this helps!

Please or to participate in this conversation.