dongyun8075 2010-02-23 18:50 采纳率: 100%
浏览 70
已采纳

简单的代码? PHP脚本从中央服务器提取update.zip并将其解压缩到本地文件夹!

Can someone post code or point to a working example of a php script that opens a known zip file located on a remote server (via http) and extracts the contents of that zip file to a folder on the same server as the calling script?

Server A calls out for zip file located on Server B
Server B sends the zip file over to server A
Server A extracts the contents of the Zip to Directory C (pub_html) on Server A

I've been going around and around on how to get this to work and it really seems like it should be super simple with lots of examples, but I can find none.

  • 写回答

3条回答 默认 最新

  • dtwkt46424 2010-02-23 19:14
    关注

    Here you go.

    Alter $filename and $dest_folder at the top accordingly. $dest_folder is currently set to current folder (where the PHP script itself resides).

    <?php
    
    $filename = 'http://someplace.com/somezipfile.zip';
    $dest_folder = '.';
    
    $out_file = fopen(basename($filename), 'w');
    $in_file = fopen($filename, 'r');
    while ($chunk = fgets($in_file)) {
        fputs($out_file, $chunk);
    }
    fclose($in_file);
    fclose($out_file);
    
    $zip = new ZipArchive();
    $result = $zip->open(basename($filename));
    if ($result) {
        $zip->extractTo($dest_folder);
        $zip->close();
    }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭