全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 837|回复: 10

大家有没有php下载zip文件的代码

[复制链接]
发表于 2019-10-11 21:08:35 | 显示全部楼层 |阅读模式
网站要转移打包好了,由于是虚拟空间不支持wget命令,想弄个php代码下载远程空间zip文件,下面代码有问题,不过类似这样的,以前有个这样的php下载文件,可惜不知道在哪里去了

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta>
  5. <meta charset="utf-8" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <title>远程下载文件</title>
  8. <form method="post">
  9. <input name="url" size="50" />
  10. <input name="submit" type="submit" />
  11. </form>
  12. <?php
  13. // maximum execution time in seconds
  14. set_time_limit (24 * 60 * 60);
  15. if (!isset($_POST['submit'])) die();
  16. // folder to save downloaded files to. must end with slash
  17. $destination_folder = 'temp/';
  18.   
  19. $url = $_POST['url'];
  20. $newfname = $destination_folder . basename($url);
  21. $file = fopen ($url, "rb");
  22. if ($file) {
  23. $newf = fopen ($newfname, "wb");
  24. if ($newf)
  25. while(!feof($file)) {
  26. fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
  27. }
  28. }
  29. if ($file) {
  30. fclose($file);
  31. }
  32. if ($newf) {
  33. fclose($newf);
  34. }
  35. ?>
  36. </body>
  37. </html>
复制代码
发表于 2019-10-11 21:12:10 | 显示全部楼层
这种主机,在这个年代是没有人用的,打包下载都不支持,正常解压,打包都是基本的功能
 楼主| 发表于 2019-10-11 21:13:47 | 显示全部楼层
jdunion 发表于 2019-10-11 21:12
这种主机,在这个年代是没有人用的,打包下载都不支持,正常解压,打包都是基本的功能 ...

用的是阿里云的虚拟空间,想把这个香港空间打包下载到阿里云的空间
发表于 2019-10-11 21:17:05 | 显示全部楼层
yabuy 发表于 2019-10-11 21:13
用的是阿里云的虚拟空间,想把这个香港空间打包下载到阿里云的空间


你用FTP一个一个的下载文件吧,今晚肯定能完成,数据库做好备份也下载
发表于 2019-10-11 21:19:16 | 显示全部楼层
阿里云虚拟机支持的

 楼主| 发表于 2019-10-11 21:21:11 | 显示全部楼层
itbobo 发表于 2019-10-11 21:19
阿里云虚拟机支持的

不是解压缩啊!是把其他空间的文件下载到阿里云虚拟空间里面啊!不想上传啊!2个多g文件这得下载和上传到什么时候去,以前有这个php文件,好久没用虚拟空间不知道弄在哪里去了
发表于 2019-10-11 22:10:36 | 显示全部楼层
代码网上一抓一大把,自己随便改改就能用。
不过2个g还是别指望php了,下一会就超时了,还是ftp慢慢传吧
发表于 2019-10-11 22:30:46 来自手机 | 显示全部楼层
在目标空间做个上传接收,然后在zip机器用命令行curl 直接POST @file上传?
 楼主| 发表于 2019-10-11 22:38:44 | 显示全部楼层
逸笙 发表于 2019-10-11 22:30
在目标空间做个上传接收,然后在zip机器用命令行curl 直接POST @file上传?

只能用国内vps下载本地再上传了。
 楼主| 发表于 2019-10-11 22:57:48 | 显示全部楼层
本帖最后由 yabuy 于 2019-10-11 23:06 编辑

谷歌搜索找了个自己改下代码,大家需要就拿去吧
  1. <?php
  2. if (isset($_POST['url']) and !empty($_POST['url'])) {
  3.         set_time_limit (0);


  4.         function microtime_float() {
  5.                 list($usec, $sec) = explode(" ", microtime());
  6.                 return ((float)$usec + (float)$sec);
  7.         }
  8.         function RealSize($size) {
  9.                 if ($size < 1024) return $size . ' Byte';
  10.                 if ($size < 1048576) return round($size / 1024, 2) . ' KB';
  11.                 if ($size < 1073741824) return round($size / 1048576, 2) . ' MB';
  12.                 if ($size < 1099511627776) return round($size / 1073741824, 2) . ' GB';
  13.         }
  14.         function wrjs() {
  15.                 global $current, $total, $size, $time, $inittime, $temptime, $initsize;
  16.                 $k = "";
  17.                 $per = round(($current / $total) * 100);
  18.                 $temptime2 = microtime_float();
  19.                 if ($per == 100 || ($temptime2 - $temptime > 1)) {
  20.                         $speed = $current / ($temptime2 - $inittime);
  21.                         $formatespeed = RealSize($speed) . '/s';
  22.                         $formatetotal = RealSize($total);
  23.                         $formatecurrent = RealSize($current);
  24.                         $pasttime = '已用时:' . round($temptime2 - $inittime) . '秒';
  25.                         $lasttime = '&nbsp;&nbsp;估计还要:' . round(($total - $current) / $speed) . '秒';
  26.                         $str = $per . '|' .$formatespeed.'|'. $pasttime . $lasttime . '|' . $formatecurrent . '|' . $formatetotal;
  27.                         @file_put_contents('downinfo.txt', $str);
  28.                         $temptime = $temptime2;
  29.                         $initsize = $current;
  30.                 }
  31.         }


  32.         $destination_folder = './';
  33.         $url = $_POST['url'];
  34.         $info = get_headers($url, 1);
  35.         $total = $info['Content-Length'];
  36.         $current = 0;
  37.         $newfname = $destination_folder . basename($url);
  38.         $file = fopen ($url, "rb");
  39.         $inittime = $temptime = microtime_float();
  40.         $initsize = 0;
  41.         if ($file) {
  42.                 $newf = fopen ($newfname, "wb");
  43.                 if ($newf)
  44.                         while (!feof($file)) {
  45.                         $str = fread($file, 1024 * 8);
  46.                         $current += strlen($str);
  47.                         fwrite($newf, $str, 1024 * 8);
  48.                         wrjs();
  49.                 }
  50.                 echo '<center>下载完毕,共计用时:' . round(microtime_float() - $inittime) . '秒</center>';
  51.         }
  52.         if ($file) {
  53.                 fclose($file);
  54.         }
  55.         if ($newf) {
  56.                 fclose($newf);
  57.         }
  58.         exit;
  59. }
  60. if (isset($_GET['getinfo'])) {
  61.                 $arr = file_get_contents('downinfo.txt');
  62.                 if ($arr) {
  63.                         header("Content-type: text/html; charset=utf-8");
  64.                         echo $arr;
  65.                 }
  66.                 exit;
  67.         }
  68. ?>
  69. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  70. <html xmlns="http://www.w3.org/1999/xhtml">
  71. <head>
  72. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  73. <title>远程下载</title>
  74. <style>
  75. *{font-size:12px;}
  76. .bar1 {background: url("/images/progress_bar_null.gif"); position:relative; text-align:left; height:13px; width:540px; border:1px solid #505050;margin:0 auto;}
  77. .bar2 {background: url("/images/progress_bar.gif"); position:relative; text-align:left; height:13px; width:0%;}
  78. .info{width:540px;margin:20px auto;font-size:12px;}
  79. </style>
  80. <script type="text/javascript">
  81. <!--
  82.     var isstart=false;
  83.     function check() {
  84.         if (g('downurl').value=="") {
  85.             alert('为空不能提交');
  86.             return false;
  87.         }
  88.         setTimeout("startdown()",2000);
  89.         return true;
  90.     }
  91.     function frameload() {
  92.         if (isstart) {
  93.             downfinish();
  94.         }
  95.     }
  96.     function downfinish() {
  97.         isstart=false;
  98.         clearInterval(timename);
  99.     }
  100.     function startdown() {
  101.         g('downinfo').style.display="block";
  102.         isstart=true;
  103.         timename=setInterval("getinfo();",500);
  104.     }
  105.     function resetinfo(p,s,t,c,tl) {
  106.         g('down_status').style.width=p+"%";
  107.         g('speed').innerHTML='平均速率:'+s;
  108.         g('time').innerHTML='时间信息:'+t;
  109.         g('current').innerHTML='已下载:'+c;
  110.         g('total').innerHTML='文件大小:'+tl;
  111.         if (p==100) {
  112.             clearInterval(timename);
  113.         }
  114.     }
  115.     function getinfo() {
  116.         if (isstart) {
  117.             ajax({
  118.                 url: "<?php echo basename(__FILE__);?>?getinfo="+Math.random(),
  119.                 data: "is=ajax" ,
  120.                 success: function (responseText) {
  121.                     arr=responseText.split('|');
  122.                     if (arr.length==5) {
  123.                         resetinfo(arr[0],arr[1],arr[2],arr[3],arr[4]);
  124.                     } else {
  125.                         alert(responseText);
  126.                     }
  127.                 }
  128.             });
  129.         }
  130.         else {
  131.             clearInterval(timename);
  132.         }
  133.     }
  134.     function ajax(s) {
  135.         var a = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  136.         with(a) {
  137.             open("POST", s.url, true);
  138.             setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  139.             send(s.data);
  140.             onreadystatechange = function () {
  141.                 readyState == 4 && status == 200 ? s.success(responseText) : null
  142.             }
  143.         }
  144.     };
  145.     function g(ob) {
  146.         return document.getElementById(ob);
  147.     }

  148. //-->
  149. </script>
  150. </head>
  151. <body>
  152. <center><form method="post" id="urlform" target="downframe" onsubmit="return check();">
  153. <div style="display:none;"><iframe name="downframe" src="about:blank"></iframe></div>
  154. <input name="url" id='downurl' size="50" />
  155. <input name="submit" value="提交下载地址" type="submit" />
  156. </form></center>
  157. <div id="downinfo" style="margin-top:30px;display:none;">
  158.     <div class="bar1" id="upload_status_wrap" align="center">
  159.         <div class="bar2" id="down_status"></div>
  160.     </div>
  161.     <div class="info">
  162.         <div id="speed">&nbsp;</div>
  163.         <div id="time">&nbsp;</div>
  164.         <div id="current">&nbsp;</div>
  165.         <div id="total">&nbsp;</div>
  166.     </div>
  167. </div>
  168. <script language="javascript">
  169. </script>
  170. </body>
  171. </html>
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-4-25 13:35 , Processed in 0.068250 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表