create and download zip file using php

前端 未结 5 732
借酒劲吻你
借酒劲吻你 2020-12-10 21:00

i am trying to create a zip file(using php) for this i have written the following code:

$fileName = \"1.docx,2.docx\";
$fileNames = explode(\',\', $fileName)         


        
5条回答
  •  爱一瞬间的悲伤
    2020-12-10 21:30

    ... it work for me

    public function downloadall(){
    
            $createdzipname = 'myzipfilename';
    
            $this->load->library('zip');
            $this->load->helper('download');
            $cours_id = $this->input->post('todownloadall');
            $files = $this->model_travaux->getByID($cours_id); 
    
            // create new folder 
            $this->zip->add_dir('zipfolder');
    
            foreach ($files as $file) {
                $paths = 'http://localhost/uploads/'.$file->file_name.'.docx';
                // add data own data into the folder created
                $this->zip->add_data('zipfolder/'.$paths,file_get_contents($paths));    
            }
            $this->zip->download($createdzipname.'.zip');
        }
    

提交回复
热议问题