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

eggplantSword's avatar

How does the storage:link work?

I ran this command but when the files in storage/app/public change the files in public/storage remain the same, what is the purpose of doing the link?

The reason I ask is because I want to create a zip with all the files available ( that part is done) but after the zip is created I want to delete all the files that are in public/storage and also the ones in storage/app/public I thought that when the files were deleted from one they would be also deleted from the other.

Could someone help me understand how it actually works. How should I go about deleted the files in both places correctly?

0 likes
4 replies
jlrdw's avatar

They shouldn't be in both, the link points to storage, so they show in public. Just fyi putting them in storage does not protect them they are still public, I usually just put them in public.

For user images that need protecting I put them in a separate folder all together and use a script to display the image.

How did they get in both folders I'm curious about that.

eggplantSword's avatar

@jlrdw ok so I should save the Excel file to the public? I'm doing that like this, how should I change it to save in the public folder not the storage folder

Excel::store(new SurveyReport($items), $name . '.xlsx', 'public');

In my filesystems.php the public looks like this

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

I ran the storage:link when there were files in the storage/app/public and they just kinda copied over to public/storage .

So where should I delete the files from?

jlrdw's avatar

If that's the case and your storage link worked properly just store them under storage and that's where you would delete them from.

And you can have more than one folder under storage separate for Excel files versus images.

Definitely practice this sort of thing before using in production.

eggplantSword's avatar

I created a new disk driver to save in the public folder like you suggested

'report_upload' => [
            'driver' => 'local',
            'root' => public_path() . '/reports',
        ],

And now I save those files in public/reports so all the files are there now (these are created using jobs), after that I have another Job to create a zip and delete the files, like this

$zip = new ZipArchive;

        if (true === ($zip->open('ReportesTodos.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE))) {
            foreach (Storage::disk('report_upload')->files() as $name) {
                $name = basename($name);
                $zip->addFile(public_path('reports\' . $name), $name);
            }
            $zip->close();
        }

//        download zip 
//        return response()->download(public_path('ReportesTodos.zip'), 'ReportesTodos.zip');


        if (file_exists(public_path('ReportesTodos.zip'))) {
            foreach (Storage::disk('report_upload')->files() as $name) {
                $name = basename($name);
                Storage::disk('report_upload')->delete($name);
            }
        }

Would this be the correct way to remove the files ? What would you recommend, just download the zip after the jobs are all done or notify the user to download it from a separate page? I don't have emails setup on this project on the server in order to send it that way.

Please or to participate in this conversation.