Search
 
SCRIPT & CODE EXAMPLE
 

PHP

download laravel 8 zip

<?php

namespace AppHttpControllers;

use File;
use ZipArchive;
use IlluminateHttpRequest;

class ZipController extends Controller
{
    public function index() 
    {
    	$zip = new ZipArchive;
   
        $fileName = 'zipFileName.zip';
   
        if ($zip->open(public_path($fileName), ZipArchive::CREATE) === TRUE)
        {
        	// Folder files to zip and download
        	// files folder must be existing to your public folder
            $files = File::files(public_path('files'));
   			
   			// loop the files result
            foreach ($files as $key => $value) {
                $relativeNameInZipFile = basename($value);
                $zip->addFile($value, $relativeNameInZipFile);
            }
             
            $zip->close();
        }
    	
    	// Download the generated zip
        return response()->download(public_path($fileName));
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: delete mysql php 
Php :: laravel launch only one dusk test 
Php :: php get first word of string 
Php :: php var_export to string 
Php :: redirect woocommerce thank you 
Php :: dompdf with qr code 
Php :: store image in storage laravel 
Php :: installing bootstrap ui in laravel app 
Php :: laravel joins 
Php :: php return a json response 
Php :: wc php get product permalink 
Php :: PHP file reading modes with explaination 
Php :: globals in php 
Php :: localhost didn’t send any data 
Php :: livewire not working 
Php :: laravel curl package 
Php :: laravel check if exists in table 
Php :: Fatal error: Allowed memory size of 1610612736 bytes exhausted but already allocated 1.75G 
Php :: mysqli_real_connect(): (HY000/2002): No such file or directory 
Php :: php check valid time format 
Php :: php unset reference 
Php :: nova laravel image 
Php :: Fatal error: Exception thrown without a stack frame in Unknown on line php 
Php :: php array extract value 
Php :: php new stdClass object 
Php :: laravel throw function 
Php :: how to get week start date in php 
Php :: laravel query builder select first 
Php :: wordpress php query randomise 
Php :: laravel blade shorthand if 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =