- Timestamp:
- 10/24/21 23:23:54 (3 years ago)
- Branches:
- develop, master
- Children:
- df6e9ec
- Parents:
- fa80fbe
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Controllers/Dashboard/DepartmentsController.php
rfa80fbe r94f05dc 47 47 48 48 $users = User::all(); 49 Notification::send($users, new NewDepartmentCreated("New department created"));50 49 51 50 $department->save(); … … 127 126 try { 128 127 $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); 129 $flag = false;130 131 128 foreach ($files as $file) { 132 129 … … 154 151 $department = Department::find($id); 155 152 156 $FileSystem = new Filesystem(); 157 $zip_file = Storage::disk('uploads')->path('Department.zip'); 153 $zip_file=Storage::disk('uploads')->path('Department.zip'); 158 154 $zip = new \ZipArchive(); 159 155 $zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); 160 $path = Storage::disk('uploads')->path($department->location) . DIRECTORY_SEPARATOR;156 $path = Storage::disk('uploads')->path($department->location); 161 157 162 try {158 try { 163 159 $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); 164 160 foreach ($files as $file) { 161 162 // We're skipping all subfolders 165 163 if (!$file->isDir()) { 166 164 $filePath = $file->getRealPath(); … … 169 167 $zip->addFile($filePath, $relativePath); 170 168 } 169 } 171 170 $zip->close(); 172 $headers = array('Content-Type' => 'application/octet-stream' ,);173 $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . $department->name . '.zip';171 $headers = array('Content-Type' => 'application/octet-stream'); 172 $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . '- Departments.zip'; 174 173 return response()->download($zip_file, $zip_new_name, $headers); 175 174 } 176 } 177 catch(\Exception $e) { 178 Alert::flash("This department has no files", "warning"); 175 catch(\Exception $e){ 176 Alert::flash("All departments are empty", "warning"); 179 177 return redirect()->back(); 180 }178 } 181 179 } 182 180 }
Note:
See TracChangeset
for help on using the changeset viewer.