PHP 下载多个文件并保存它们的安全方式 [英] PHP Safe way to download mutliple files and save them

查看:20
本文介绍了PHP 下载多个文件并保存它们的安全方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方法来下载大量文件并使用 PHP 将它们保存到文件系统.这是一个部署工具,我打算使用一个 Zip 文件,因为我只是调用了一些解压缩代码,这很简单.但是,ZIP 功能是一个并非每个人都拥有的扩展.

I need a way to download a lot of files and save them to the file system with PHP. This is for a deployment tool, and I was planning on using a Zip file, since I just call some unzip code and it's simple. However, the ZIP functionality is an extension that not everyone has.

我现在唯一的另一个想法是将所有内容以 Base64 编码的形式压缩到一个文件中,对其进行解码并将其写回.这并不理想(或者是吗?).建议?

My only other idea right now is to compress everything into one file as Base64 encoded, decode it and write it back out. This isn't ideal (Or is it?). Suggestions?

推荐答案

Zip 真的不难解析,如果你能跟着一个相当简单的文件格式规范,并且愿意依靠要安装的 zlib 扩展来处理解压.

Zip is really not difficult to parse, if you can follow a rather simple file format specification and are willing to count on the zlib extension to be installed to handle the decompression.

否则,发明您自己的自定义存档文件格式,这并不难.这可能是一个非常简单的事情:

Otherwise, invent your own custom archive file format, it's not hard. It could be something a dead simple as this:

  • 前 4 个字节:存档中的文件数
  • 接下来的 4 个字节:文件名中的字节数
  • 接下来的 N 个字节:文件名
  • 接下来的 10 个字节:文件中的字节数
  • 接下来的 N 个字节:文件内容
  • 根据需要重复以上 4 行

所以一个非常简单的存档文件可能看起来像

So a very simple archive file might look like

00020007foo.txt0000000012Hello world!0007bar.txt0000000010It worked!

您当然可以通过以二进制格式存储长度(例如使用带有N"格式的 pack)、添加校验和等来改进它.但这样解释更容易.

You could of course improve it by storing lengths in binary format (e.g. using pack with the 'N' format), adding checksums, and so on. But it was easier to explain this way.

这篇关于PHP 下载多个文件并保存它们的安全方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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