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

SiNi_Si's avatar

Uploading files to public storage simlink

I'm using ajax to upload images to summernote, and all works fine to the public image directory using...

$image->move(public_path('images/users/'.$id.''), $new_name);

what do I need to change this to, to send this to my simlink storage directory?

I have checked and ran... php artisan storage:link

and it does return... The "public/storage" directory already exists.

Any help would be great thanks Si

0 likes
6 replies
grenadecx's avatar
Level 7
$image->move(public_path('images/users/'.$id.''), $new_name);

Should be

$image->move(public_path('storage/images/users/'.$id.''), $new_name);

Since the symlink is the storage folder in public_html. But yeah. take a look below on a better way to deal with it using the storage driver driver.

https://laravel.com/docs/5.7/requests#storing-uploaded-files

In default laravel installation, there's a storage disk setup that is called public.

To use it an example would be:

$path = $image->storeAs('images/users'.$id, $new_name, 'public');

This would put the file inside storage/app/public/images/users/1 which can be reached from inside public_html/storage/images/users/1

To change default path or setup a new disk, take a look at the config/filesystems.php file.

Then you could use something like

Storage::disk('public')->url($path);

To output a public url to the file, so as long as you store the path, it should be easy. I think you can omit the disk('public') if you use standard setup since it will default to the storage folder.

SiNi_Si's avatar

Thats works great for the upload. File is in storage.

how do you get it back in the blade?

I have tried to do some hard code tests but no luck yet {{ asset('storage/users/3/1953263541.png') }} or {{ asset('storage/images/users/3/1953263541.png') }}

Thanks

SiNi_Si's avatar

still no luck after everyone is saying use url()

@inject('path', 'App\Injection')

{{ url('storage/images/users/'.$path->Avitar_Image()) }}

grenadecx's avatar

Use the {{ Storage::disk('public')->url($path) }}

SiNi_Si's avatar

{{ Storage::disk('public')->url('/images/users/3/1343051701.png') }}

Please or to participate in this conversation.