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.
Use storage_path()
helper:
$zip->extractTo(storage_path('tempdir'));
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With