您现在的位置是:网站首页>PHPPHP

PHP的ZIP压缩文件方法(单文件)

左鹏07-01 10:29:19PHP4,443人已围观

简介需要开启php.ini的ZIP支持open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { return false; } //add the files //向压缩文件中添加文件 foreach($valid_files as $fi

需要开启php.ini的ZIP支持

open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {   
            return false;   
        }   
        //add the files   
        //向压缩文件中添加文件   
        foreach($valid_files as $file) {  
            $file_info_arr= pathinfo($file); 
        $filename =$file_info_arr['basename'];  
                $zip->addFile($file,$filename);   
        }   
        //debug   
        //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;   
        //close the zip -- done!   
        //关闭文件   
        $zip->close();   
        //check to make sure the file exists   
        //检测文件是否存在   
        return file_exists($destination);   
    }else{   
        //如果没有真实有效的文件返回false   
        return false;   
    }   
}


文章评论

    请先说点什么
    热门评论
    0人参与,0条评论
    正在载入评论列表...

    站点信息

    • 建站时间:2018-09-18
    • 网站程序:Spring Boot
    • 主题模板:《今夕何夕》
    • 文章统计:104条
    • 微信公众号:扫描二维码,关注我们
    登陆您的账户