I am trying to create zip file from specific folder files, it does create the zip file but .env
file (i guess any file that starts with dot) will not be include in zip files.
Question
How can I add all files from my folder to zip file regardless of their names?
code
public function downloadZip($fileName)
{
$zip = new ZipArchive;
$downloadFolder = 'downloads';
if (!file_exists($downloadFolder))
{
mkdir($downloadFolder);
}
if ($zip->open(public_path($downloadFolder.'/'.$fileName.'.zip'), ZipArchive::CREATE) === TRUE)
{
$files = File::files(public_path($fileName));
foreach ($files as $key => $value) {
$relativeNameInZipFile = basename($value);
$zip->addFile($value, $relativeNameInZipFile);
}
$zip->close();
}
return response()->download(public_path($downloadFolder.'/'.$fileName.'.zip'));
}
Screenshot