强制从 php 打开并读取 zip 文件
这可能是一个简单的问题,也可能是一个相当复杂的问题,我会让你来做决定者。
使用 PHP 打开 zip 文件、将文件解压到目录并关闭 zip 文件并不是一个复杂的类。
但是假设该文件不是 zip,但可以被 WinRar 读取,这些文件的示例例如 exe 的 SFX 存档等。
所有这些文件都有哪些因素允许WinRar 浏览它们的源代码。
另一个例子是防病毒软件,它单独扫描 EXE 中的文件?
举个例子:
$handle = fopen("an_unknown_file.abc", "rb");
while (!feof($handle))
{
//What generic code could I use to determain weather the file can be extracted ?
}
fclose($handle);
问候。
This may be a simple question or a pretty complex one, ill let you be the deciders.
Using PHP To open a zip file, extract the files to a directory and close the zip file is not a complicated class to make.
But lets say that the file is not a zip, but yet is able to be read by WinRar, examples of these files are like exe's SFX archives etc.
What factors do all these files have in conmen to allow WinRar to browse the source of them.
Another example is Anti Virus Software, that individually scan files within an EXE ?
So what an example:
$handle = fopen("an_unknown_file.abc", "rb");
while (!feof($handle))
{
//What generic code could I use to determain weather the file can be extracted ?
}
fclose($handle);
Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Zip 的规范允许将实际的“zip”文件部分嵌入到文件中的任何位置。它不一定必须从文件中的位置“0”开始。这就是自解压拉链的工作原理。它是一个小型 .exe 存根程序,其末尾附加了一个较大的 .zip 文件。
查找 zip 主要是扫描文件中 zip 文件的“幻数”,然后执行一些启发式操作来确定它是否真的是 zip 文件,或者只是碰巧包含 zip 幻数的随机文件。
.docx 文件实际上只是一个 .zip 文件,其中包含表示 Word 文件内容的各种 XML 文件。就像 .jar 是一个 zip 文件,其中包含各种不同的 Java 代码块。
Winrar 中有一堆额外的代码,用于扫描文件并查找任何可识别的“这是压缩存档”类型签名,其中之一恰好是 zip 文件的签名。
这并没有什么太神奇的。只需扫描文件并查找签名即可。
Zip's specifications allow the actual "zip" file portion to be embedded ANYWHERE within a file. It doesn't necessarily have to start at position '0' in the file. This is how self-extracting zips work. It's a small .exe stub program which has a larger .zip file appended to the end of it.
Finding a zip is mostly a matter of scanning for a zip file's "magic number" within a file, then doing a few heuristics to determine if it's really a zip file, or just something random that happens to contain a zip's magic number.
A .docx file is really just a .zip that contains various XML files representing a Word file's contents. Just like a .jar is a zip file that contains various different chunks of Java code.
Winrar's got a bunch of extra code within it to scan through a file and look for any identifiable "this is a compress archive" type signatures, one of which happens to be that of a zip file's.
There's nothing too magical about it. It's just a matter of scanning through a file and looking for signatures.
不确定你的问题到底是什么,但我认为你在这里感到困惑......文件扩展名可以被描述为人类和计算机将文件扩展名与与其一起使用的文件/程序的类型相关联的一种便捷方式。 WinRar(或任何其他程序)读取文件包含的内容,如果它可以理解它 - 它可以使用它。唯一重要的是文件格式(文件中的数据)有效并且您正在使用的程序可以处理该文件格式。
因此,如果文件采用 WinRar 可以使用的任何格式(.rar、.zip、.gz 等),则其扩展名可以是 .txt 或 .whatever,WinRar 仍然可以使用它。扩展只是为了方便。
Not sure what exactly is your question, but I think you are confusing something here... File extension can be described as just a convenient way for humans and computers to relate file extensions to the type of the file/programs that work with them. WinRar (or any other program) reads what the file contains and if it can understand it - it works with it. The only important thing is that the file format (data in the file) is valid and that the program you are using can work with this file format.
So, if a file is in any format that WinRar can work with (.rar, .zip, .gz, etc.), it's extension could be .txt or .whatever and WinRar will still be able to work with it. Extension is just for convenience.