Changeset bbcbb57


Ignore:
Timestamp:
10/25/21 00:13:21 (3 years ago)
Author:
beratkjufliju <kufliju@…>
Branches:
develop, master
Children:
68694d4
Parents:
2279f71
Message:

bug fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • app/Http/Controllers/Dashboard/DepartmentsController.php

    r2279f71 rbbcbb57  
    119119    public function downloadAll()
    120120    {
     121        $zip_file = Storage::disk('uploads')->path('Departments.zip');
     122        $zip = new \ZipArchive();
     123        $zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
    121124
    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));
    125128        try {
    126             $path = Storage::disk('uploads')->path('Departments');
    127 
    128             $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
    129129            foreach ($files as $file) {
    130130
    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                 }
     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        }
    139139                $zip->close();
    140140                $headers = array('Content-Type' => 'application/octet-stream');
    141141                $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . '- Departments.zip';
    142142                return response()->download($zip_file, $zip_new_name, $headers);
    143         }
     143                }
     144
    144145        catch(\Exception $e){
    145146           Alert::flash("All departments are empty", "warning");
Note: See TracChangeset for help on using the changeset viewer.