将远程文件添加到 zip 文件 [英] adding remote files to a zip file

查看:58
本文介绍了将远程文件添加到 zip 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将文件从另一个带有 php zip 扩展名的服务器添加到 zip 文件中?IE.

Is there a way to add files to a zip file from another server with php's zip extension? ie.

addFile(array('localfile.txt,'http://www.domain.com/remotefile.txt'))
//(that obviously does not work)

我想我可以将文件下载到一个临时文件夹,然后将它们添加到 zip 文件中,但我一直在寻找更自动化的解决方案或已经制作的功能

I suppose I can download the files to a temporal folder and then add them to the zip file, but I was looking for a more automated solution or a function already made

推荐答案

使用 file_get_contents() 和 ZipArchive::addFromString()

use file_get_contents() and ZipArchive::addFromString()

$zipArchiveInstance->addFromString($filename, file_get_contents($mediaUrl));

这会将远程获取的内容直接写入您的 php 对象(无需写入/读取临时文件)

This writes the contents fetched remotely straight into your php object (no need to write/read temp file)

这篇关于将远程文件添加到 zip 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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