zip扩展下载地址:http://pecl.php.net/package/zip
<?php
$zip = new ZipArchive;
if ($zip->open('example.zip', ZipArchive::CREATE) === TRUE) {
$fileUrl = 'https://www.example.com/path/to/file.txt'; // 网络文件的URL
$fileContents = file_get_contents($fileUrl); // 获取文件内容
$zip->addFromString('file.txt', $fileContents); // 添加文件到ZIP
$zip->close();
echo 'ZIP文件创建成功!';
} else {
echo 'ZIP文件创建失败!';
}
?>