Implementation of PHP single file compression function

不言
Release: 2023-03-24 13:44:02
Original
1024 people have browsed it

The content of this article is about the implementation of the PHP single file compression function. The correct writing method of recursion has a certain reference value. Now I share it with everyone. Friends in need can refer to it

function zip_file(string $filename){
  if(!is_file($filename)){
    return false;
  }
  $zip=new ZipArchive();
  $zipName=basename($filename).'.zip';
  //打开指定压缩包,不存在则创建,存在则覆盖
  if($zip->open($zipName,ZipArchive::CREATE|ZipArchive::OVERWRITE)){
    //将文件添加到压缩包中
    if($zip->addFile($filename)){
      @unlink($filename);
    }
    $zip->close();
    return true;
  }else{
    return false;
  }
}
Copy after login

Related recommendations:

php function to implement decompression function

The above is the detailed content of Implementation of PHP single file compression function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!