Changeset 507ade0 for app/Http


Ignore:
Timestamp:
10/25/21 12:59:43 (3 years ago)
Author:
beratkjufliju <kufliju@…>
Branches:
develop, master
Children:
13ff930
Parents:
bdda09f
Message:

bug fixes

File:
1 edited

Legend:

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

    rbdda09f r507ade0  
    276276    public function downloadfolder(Request $request, $id)
    277277    {
    278         try {
    279278            $folder = Folder::find($id);
    280279            $FileSystem = new Filesystem();
    281             $zip_file = Storage::disk('uploads')->path('Folder.zip');
    282             $zip = new \ZipArchive();
    283             $zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
    284 
    285             $path = Storage::disk('uploads')->path($folder->department->location . DIRECTORY_SEPARATOR . $folder->name);
    286 
    287             $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
    288 
    289             $filesInDoc = $FileSystem->allFiles($path);
    290 
    291             foreach ($files as $file) {
    292                 if (!$file->isDir()) {
    293                     $filePath = $file->getRealPath();
    294                     // extracting filename with substr/strlen
    295                     $relativePath = substr($filePath, strlen($path) + 1);
    296                     $zip->addFile($filePath, $relativePath);
     280
     281            if($folder->no_of_files > 0) {
     282                $zip_file = Storage::disk('uploads')->path('Folder.zip');
     283                $zip = new \ZipArchive();
     284                $zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
     285
     286                $path = Storage::disk('uploads')->path($folder->department->location . DIRECTORY_SEPARATOR . $folder->name);
     287
     288                $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
     289
     290                $filesInDoc = $FileSystem->allFiles($path);
     291
     292                foreach ($files as $file) {
     293                    if (!$file->isDir()) {
     294                        $filePath = $file->getRealPath();
     295                        // extracting filename with substr/strlen
     296                        $relativePath = substr($filePath, strlen($path) + 1);
     297                        $zip->addFile($filePath, $relativePath);
     298                    }
    297299                }
    298             }
    299             $zip->close();
    300             $headers = array('Content-Type' => 'application/octet-stream',);
    301             $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . $folder->name . '.zip';
    302             return response()->download($zip_file, $zip_new_name, $headers);
    303         }
    304         catch (\Exception $e) {
    305             //abort(403, "No files found");
     300                $zip->close();
     301                $headers = array('Content-Type' => 'application/octet-stream',);
     302                $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . $folder->name . '.zip';
     303                return response()->download($zip_file, $zip_new_name, $headers);
     304            }
     305        else {
    306306            Alert::flash("This folder has no files", "warning");
    307307            return redirect()->back();
Note: See TracChangeset for help on using the changeset viewer.