- Timestamp:
- 10/25/21 00:21:56 (3 years ago)
- Branches:
- develop, master
- Children:
- c08466c
- Parents:
- 68694d4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Controllers/Dashboard/DepartmentsController.php
r68694d4 r2740efc 119 119 public function downloadAll() 120 120 { 121 $zip_file = Storage::disk('uploads')->path('Departments.zip'); 122 $zip = new \ZipArchive(); 123 $zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); 121 try { 122 $zip_file = Storage::disk('uploads')->path('Departments.zip'); 123 $zip = new \ZipArchive(); 124 $zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); 124 125 125 $path = Storage::disk('uploads')->path('Departments');126 $path = Storage::disk('uploads')->path('Departments'); 126 127 127 try {128 128 $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); 129 }130 catch(\Exception $e){131 Alert::flash("All departments are empty", "warning");132 return redirect()->back();133 }134 129 135 130 foreach ($files as $file) { 136 131 137 // We're skipping all subfolders 138 if (!$file->isDir()) { 139 $filePath = $file->getRealPath(); 140 // extracting filename with substr/strlen 141 $relativePath = substr($filePath, strlen($path) + 1); 142 $zip->addFile($filePath, $relativePath); 132 // We're skipping all subfolders 133 if (!$file->isDir()) { 134 $filePath = $file->getRealPath(); 135 // extracting filename with substr/strlen 136 $relativePath = substr($filePath, strlen($path) + 1); 137 $zip->addFile($filePath, $relativePath); 138 } 143 139 } 140 $zip->close(); 141 $headers = array('Content-Type' => 'application/octet-stream'); 142 $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . '- Departments.zip'; 143 return response()->download($zip_file, $zip_new_name, $headers); 144 144 } 145 $zip->close(); 146 $headers = array('Content-Type' => 'application/octet-stream'); 147 $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . '- Departments.zip'; 148 return response()->download($zip_file, $zip_new_name, $headers); 149 145 catch(\Exception $e){ 146 Alert::flash("All departments are empty", "warning"); 147 return redirect()->back(); 148 } 150 149 } 151 150
Note:
See TracChangeset
for help on using the changeset viewer.