将远程文件添加到zip文件(adding remote files to a zip file)

编程入门 行业动态 更新时间:2024-10-24 16:26:39
将远程文件添加到zip文件(adding remote files to a zip file)

有没有办法用另外的服务器使用php的zip扩展名将文件添加到zip文件中? 即。

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

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

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)

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()

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

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

use file_get_contents() and ZipArchive::addFromString()

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

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

更多推荐

本文发布于:2023-08-04 23:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1424604.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   zip   adding   file   files

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!