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