Changeset 159e7df for app/Http/Controllers/Dashboard
- Timestamp:
- 10/24/21 21:42:47 (3 years ago)
- Branches:
- develop, master
- Children:
- 169fcc8
- Parents:
- 1c17e70
- Location:
- app/Http/Controllers/Dashboard
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Controllers/Dashboard/DepartmentsController.php
r1c17e70 r159e7df 124 124 $zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); 125 125 $path = Storage::disk('uploads')->path('Departments'); 126 $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));127 $flag=false;128 126 129 foreach ($files as $file)130 {131 if(File::all()->count() > 0) {127 try { 128 $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); 129 $flag = false; 132 130 133 // We're skipping all subfolders 134 if (!$file->isDir()) { 135 $filePath = $file->getRealPath(); 136 // extracting filename with substr/strlen 137 $relativePath = substr($filePath, strlen($path) + 1); 138 $zip->addFile($filePath, $relativePath); 131 foreach ($files as $file) { 132 133 // We're skipping all subfolders 134 if (!$file->isDir()) { 135 $filePath = $file->getRealPath(); 136 // extracting filename with substr/strlen 137 $relativePath = substr($filePath, strlen($path) + 1); 138 $zip->addFile($filePath, $relativePath); 139 } 139 140 } 140 } 141 else 142 { 143 $flag=true; 144 break; 145 } 141 $zip->close(); 142 $headers = array('Content-Type' => 'application/octet-stream'); 143 $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . '- Departments.zip'; 144 return response()->download($zip_file, $zip_new_name, $headers); 146 145 } 147 if(!$flag) { 148 $zip->close(); 149 $headers = array('Content-Type' => 'application/octet-stream'); 150 $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . '- Departments.zip'; 151 return response()->download($zip_file, $zip_new_name, $headers); 152 } 153 else { 154 Alert::flash("All departments are empty", "warning"); 146 catch(\Exception $e){ 147 Alert::flash("All departments are empty", "warning"); 155 148 return redirect()->back(); 156 149 } … … 166 159 $zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); 167 160 $path = Storage::disk('uploads')->path($department->location) . DIRECTORY_SEPARATOR; 168 $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));169 161 170 $filesInDept = $FileSystem->allFiles($path); 171 172 if(!empty($filesInDept)) { 173 foreach ($files as $file) { 174 if (!$file->isDir()) { 175 $filePath = $file->getRealPath(); 176 // extracting filename with substr/strlen 177 $relativePath = substr($filePath, strlen($path) + 1); 178 $zip->addFile($filePath, $relativePath); 179 } 162 try{ 163 $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); 164 foreach ($files as $file) { 165 if (!$file->isDir()) { 166 $filePath = $file->getRealPath(); 167 // extracting filename with substr/strlen 168 $relativePath = substr($filePath, strlen($path) + 1); 169 $zip->addFile($filePath, $relativePath); 170 } 171 $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'; 174 return response()->download($zip_file, $zip_new_name, $headers); 180 175 } 181 $zip->close(); 182 $headers = array('Content-Type' => 'application/octet-stream',); 183 $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . $department->name . '.zip'; 184 return response()->download($zip_file, $zip_new_name, $headers); 185 } 186 else{ 176 } 177 catch(\Exception $e) { 187 178 Alert::flash("This department has no files", "warning"); 188 179 return redirect()->back(); 189 } 190 180 } 191 181 } 192 182 } -
app/Http/Controllers/Dashboard/FoldersController.php
r1c17e70 r159e7df 284 284 $path = Storage::disk('uploads')->path($folder->department->location . DIRECTORY_SEPARATOR . $folder->name); 285 285 286 $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));287 288 $filesInDoc = $FileSystem->allFiles($path); 289 290 if(empty(!$filesInDoc)) { 286 try { 287 $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); 288 289 $filesInDoc = $FileSystem->allFiles($path); 290 291 291 foreach ($files as $file) { 292 292 if (!$file->isDir()) { … … 300 300 $headers = array('Content-Type' => 'application/octet-stream',); 301 301 $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . $folder->name . '.zip'; 302 303 } 304 else{302 return response()->download($zip_file, $zip_new_name, $headers); 303 } 304 catch (\Exception $e) { 305 305 Alert::flash("This folder has no files", "warning"); 306 306 return redirect()->back(); 307 307 } 308 309 308 } 310 309
Note:
See TracChangeset
for help on using the changeset viewer.