用其他方式修改zip文件中的文件 [英] Modify files inside zip file, other way

查看:113
本文介绍了用其他方式修改zip文件中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改zip文件中的某些文件.我尝试使用zip类,它可以正常工作:

I want to modify some files inside zip file. I tried using the class zip and it works:

$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
$zip->extractTo('./', 'test.txt');

$fp=fopen("test.txt","a");

fputs($fp,"Hello"."\n");
fclose($fp);

$zip->addFile('test.txt');
$zip->close();

unlink ("test.txt");    

}

是否可能不创建用于修改,提取,重新打包等的临时文件.相反,只能在zip文件内部修改我要更改的目标文件.

Is it possible to not create temp file for modify, extract, repack, etc. Instead, only modify inside of zip file the target file I want change.

如果无法使用zip文件,则没有问题.我可以使用其他压缩文件格式,例如tar等.我需要一些格式让我在其中压缩许多文件并在其内容中进行修改.

If it is not possible with zip files no problem. I can use other compression file formats, such as tar, etc. I need some format let me compress many files inside and modify this in his contents.

推荐答案

如果您压缩文件(从而在容器中更改文件的大小),则常规存档格式将不允许您就地修改文件,因为任何修改将导致大小更改,并且文件将不合适.

If you compress files (and thus change their size within the container), then regular archive formats won't let you modify the files in-place, because any modification will cause size change and the file won't fit well.

支持按文件压缩的​​文件系统(NTFS,我们的SolFS等)通过压缩文件的几个块(扇区,页面)并将其放入更少的块中来实现.而且文件系统通常具有额外的可用空间.因此,修改文件会导致文件大小改变,从而导致将块写入磁盘原始扇区以外的其他位置.

Filesystems that support per-file compression (NTFS, our SolFS etc) do this by compressing several blocks (sectors, pages) of the file and trying to put them to smaller number of blocks. Also filesystems usually have extra free space. So modification of the file, when it leads to change of the file size, causes blocks to be written to different place other than the original sectors of the disk.

这表示,没有 compression 文件格式适合您.TAR不是压缩格式(即文件未压缩存储),但是如果您再次修改文件而导致大小改变,TAR将无济于事.

This said, no compression file format will work for you. TAR is not a compression format (i.e. files are stored uncompressed) but again if you modify the file and this causes size change, TAR won't help.

我可以看到的唯一选项是支持压缩的文件中的文件系统(例如Codebase Filesystem,我们的SolFS).不幸的是,Codebase文件系统和SolFS都没有PHP接口.

The only option I can see is a filesystem in a file (eg. Codebase Filesystem, our SolFS) that supports compression. Unfortunately neither Codebase filesystem nor SolFS have PHP interface.

这篇关于用其他方式修改zip文件中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆