create and download zip file using php

前端 未结 5 744
借酒劲吻你
借酒劲吻你 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:19

    /* create zip folder */

    public function zip(){
        $getImage = $this->cart_model->getImage();
        $zip = new ZipArchive;
        $auto = rand();
        $file = date("dmYhis",strtotime("Y:m:d H:i:s")).$auto.'.zip';
        if ($zip->open('./download/'.$file,  ZipArchive::CREATE)) {
            foreach($getImage as $getImages){
                $zip->addFile('./assets/upload/photos/'.$getImages->image, $getImages->image);
            }
            $zip->close();
            $downloadFile = $file;
            $download = Header("Location:http://localhost/projectname/download/".$downloadFile);
    
    
        }
    }
    

    model------

    /* get add to cart image */

    public function getImage(){
        $user_id = $this->session->userdata('user_id');
        $this->db->select('tbl_cart.photo_id, tbl_album_image.image as image');
        $this->db->from('tbl_cart');
        $this->db->join('tbl_album_image', 'tbl_album_image.id = tbl_cart.photo_id', 'LEFT');
        $this->db->where('user_id', $user_id);
        return $this->db->get()->result();
    }
    

提交回复
热议问题