Private Temporary Storage Directory in Laravel

Viewed 11182

With Laravel, I assume that the storage/ folder is a good place to unzip some temporary files into. So in the code, I mentioned this path: storage/tempdir. Like the following:

$zip = new ZipArchive();
$zip->open($request->excelFile->path());
$dir = "storage/tempdir";
$zip->extractTo($dir);

But the unzipped files end up in public/storage/tempdir/

This way they are accessible for public, and I don't want that.

How can I refer to storage/tempdir on both my Windows and Linux machines? tnx.

2 Answers

https://github.com/spatie/temporary-directory

This package offers a better solution as it allows multiple concurrent extractions without their files being mixed into the same fixed folder of storage_path('tempdir')

Using a fixed folder may work for simple cases, but once scaled up, the issues it creates are hard to troubleshoot and debug.

Related