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

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器