Changeset 2740efc for app


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

bug fixes

File:
1 edited

Legend:

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

    r68694d4 r2740efc  
    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);
     121        try {
     122            $zip_file = Storage::disk('uploads')->path('Departments.zip');
     123            $zip = new \ZipArchive();
     124            $zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
    124125
    125         $path = Storage::disk('uploads')->path('Departments');
     126            $path = Storage::disk('uploads')->path('Departments');
    126127
    127         try {
    128128            $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
    129         }
    130         catch(\Exception $e){
    131             Alert::flash("All departments are empty", "warning");
    132             return redirect()->back();
    133         }
    134129
    135130            foreach ($files as $file) {
    136131
    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                }
    143139            }
     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);
    144144        }
    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    }
    150149    }
    151150
Note: See TracChangeset for help on using the changeset viewer.