开发者

adding remote files to a zip file

开发者 https://www.devze.com 2023-01-01 17:04 出处:网络
Is there a way to add files to a zip file from another server with php\'s zip extension? ie. addFile(array(\'localfile.t开发者_开发知识库xt,\'http://www.domain.com/remotefile.txt\'))

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

addFile(array('localfile.t开发者_开发知识库xt,'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


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)


It's not hard to read remote files in PHP.

file_get_contents("http://example.com/remote.txt");

Or to copy them locally:

copy("http://example.com/remote.txt", "/tmp/local.txt");

Whichever way you do it, the contents are going to have to be transferred to a local temp folder or memory before you can do anything with them.


Fetch them with cURL, add them from TEMP directory.

0

精彩评论

暂无评论...
验证码 换一张
取 消