PHP使用 TbsZip 对 Zip 压缩文件进行操作
使用 TbsZip 对 Zip 压缩文件进行操作
TbsZip 是一个 PHP 的类用来读写 Zip 压缩文件包,该类无需 PHP 扩展或者是临时文件。
TbsZip 可以对压缩文档中的文件进行读、写、修改和删除操作。
/* Some code examples for TbsZip Skrol29, 2010-09-03 */ include_once('tbszip.php'); // load the TbsZip library $zip = new clsTbsZip(); // create a new instance of the TbsZip class $zip->CreateNew(); // start a new empty archive for adding files // or $zip->Open('an_existing_archive.zip'); // open an existing archive for reading and/or modifying // -------------------------------------------------- // Reading information and data in the opened archive // -------------------------------------------------- // check if a file is existing in the archive, the name must precise subfolders if any $ok = $zip->FileExists('subfolder/help.html'); // count the files stored in the archive $file_nbr = count($zip->CdFileLst); // retrieve the content of an compressed file in the archive $text1 = $zip->FileRead('readme.txt'); // retrieve the content of an compressed file in a subfolder of the archive $text2 = $zip->FileRead('subfolder/readme.txt'); if ($ok) $zip->FileExists('subfolder/help.html'); // ----------------------------- // Modifying data in the archive // ----------------------------- // add a file in the archive $zip->FileAdd('newfile.txt', $data, TBSZIP_STRING); // add the file by giving the content $zip->FileAdd('newpic1.png', './images/localpic1.png', TBSZIP_FILE); // add the file by copying a local file $zip->FileAdd('newpic2.png', './images/localpic2.png', TBSZIP_FILE, false); // add the uncompressed file by copying a local file // delete an existing file in the archive $zip->FileReplace('newfile.txt', $data, TBSZIP_STRING); // replace the file by giving the content $zip->FileReplace('newpic1.png', './images/localpic1.png', TBSZIP_FILE); // replace the file by copying a local file $zip->FileReplace('newpic2.png', './images/localpic2.png', TBSZIP_FILE, false); // replace the uncompressed file by copying a local file $zip->FileReplace('newpic3.png', false); // delete the file in the archive // cancel the last modification on the file (add/replace/delete) $zip->FileCancelModif('newpic2.png'); // ---------------------- // Applying modifications // ---------------------- $zip->Flush(TBSZIP_FILE, './save/new_archive.zip'); // apply modifications as a new local file // apply modifications as an HTTP downloaded file $zip->Flush(TBSZIP_DOWNLOAD, 'download.zip'); $zip->Flush(TBSZIP_DOWNLOAD, 'download.zip', 'application/zip'); // with a specific Content-Type // apply modifications as a downloaded file with your customized HTTP headers header("Content-type: application/force-download"); header("Content-Disposition: attachment; filename=download.zip"); header("Expires: Fri, 01 Jan 2010 05:00:00 GMT"); $zip->Flush(TBSZIP_DOWNLOAD+TBSZIP_NOHEADER); // ----------------- // Close the archive // ----------------- $zip->Close(); // stop to work with the opened archive. Modifications are not applied to the opened archive, use Flush() to commit

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PHP是一种非常流行的服务器端编程语言,它在网站开发中被广泛应用。其中,文件上传和下载是网站常用的功能之一,而PHP提供了丰富的函数和技巧来实现这些功能。在本文中,我们将详细介绍PHP中的文件上传和下载技巧,让你能够更加高效地开发网站。文件上传文件上传是指把本地计算机中的文件发送到远程服务器,上传文件后我们可以对这些文件进行存储、处理和展示等操作。在PHP中

PHP快手API接口调用技巧:如何处理接口返回的错误信息在使用PHP进行快手API接口调用时,我们经常会遇到接口返回错误的情况。对于处理接口返回的错误信息,我们需要进行合适的处理和反馈,以便提高应用程序的稳定性和用户体验。本文将介绍一些处理接口返回错误信息的技巧,并提供相应的代码示例。使用try-catch捕获异常在调用API接口时,可能会发生一些异常错误,

随着互联网的快速发展,越来越多的网站需要实现数据分页功能,以提高用户的浏览体验。在Web开发中,PHP是最流行的服务器端编程语言之一,而数据分页功能是PHP开发中不可缺少的技术。本文将介绍PHP中的分页技术在框架中的应用方法,并对比不同的分页方案的优缺点。一、传统PHP分页方法在传统PHP开发中,实现数据分页功能需要编写较多的代码,并且需要在每个页面中进行重

替换PHP中的换行符是在实际开发中经常会遇到的问题,特别是在处理文本数据时。换行符在不同操作系统中的表示方式可能不一样,通常在Windows系统中是"",在Linux系统中是""。因此,我们需要对换行符进行统一处理,以确保文本数据的格式正常。本文将深入探讨PHP中替换换行符的技巧,并提供具体的代码示例。1.使用PHP内置函数处理换行符PHP提供了一些内置函

PHP编程技巧:快速定位数组缺失数字的方法在编程中,经常会遇到需要检查数组中是否缺少某些数字的情况。这时候,我们需要一种快速有效的方法来定位数组中缺失的数字,以便及时处理。本文将介绍一种基于PHP的编程技巧,通过具体的代码示例来展示快速定位数组中缺失数字的方法。1.方法一:使用循环遍历数组首先,我们可以通过循环遍历数组的方式来检查数组中缺失的数字。具体步骤

PHP编程技巧:如何处理图片缩放在现代网页设计中,图片是不可或缺的一部分,而图片缩放是常见的操作之一。无论是在展示图片集合,还是在响应不同大小设备的需求上,图片缩放都起到了重要的作用。本文将介绍如何使用PHP编程语言处理图片缩放,并附上代码示例供参考。一、使用GD库进行图片缩放GD库是PHP中一个强大的图像处理库,我们可以使用它来实现图片缩放功能。首先,确保

PHP高并发处理技巧解析随着互联网的发展,对于网站的并发访问量要求也越来越高。而PHP作为一种开发网站的编程语言,面对高并发的访问压力,需要一些特殊的处理技巧来提高性能和稳定性。本文将介绍一些PHP高并发处理的技巧,并提供代码示例。使用PHP-FPMPHP-FPM(FastCGIProcessManager)是PHP官方提供的一个进程管理器,它可以有效地

掌握PHP开发的50个功能实现技巧与经验分享作为一名PHP开发者,我们时刻都在追求高效、高质量的代码实现。为了提高开发效率和代码质量,我们需要积累一些经验和技巧,以应对各种复杂的开发需求和挑战。在本文中,我将分享50个实现各种功能的PHP开发技巧和经验,希望对大家的PHP开发之路有所帮助。使用合适的框架:选择和熟悉一个适合自己的PHP框架,可以提高开发效率和
