将远程文件添加到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)
更多推荐
发布评论