网站要转移打包好了,由于是虚拟空间不支持wget命令,想弄个php代码下载远程空间zip文件,下面代码有问题,不过类似这样的,以前有个这样的php下载文件,可惜不知道在哪里去了
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>远程下载文件</title>
- <form method="post">
- <input name="url" size="50" />
- <input name="submit" type="submit" />
- </form>
- <?php
- // maximum execution time in seconds
- set_time_limit (24 * 60 * 60);
- if (!isset($_POST[‘submit’])) die();
- // folder to save downloaded files to. must end with slash
- $destination_folder = ‘temp/’;
- $url = $_POST[‘url’];
- $newfname = $destination_folder . basename($url);
- $file = fopen ($url, "rb");
- if ($file) {
- $newf = fopen ($newfname, "wb");
- if ($newf)
- while(!feof($file)) {
- fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
- }
- }
- if ($file) {
- fclose($file);
- }
- if ($newf) {
- fclose($newf);
- }
- ?>
- </body>
- </html>
复制代码
河北网友:这种主机,在这个年代是没有人用的,打包下载都不支持,正常解压,打包都是基本的功能
香港网友:用的是阿里云的虚拟空间,想把这个香港空间打包下载到阿里云的空间
青海网友:
你用FTP一个一个的下载文件吧,今晚肯定能完成,数据库做好备份也下载
湖北网友:阿里云虚拟机支持的
福建网友:不是解压缩啊!是把其他空间的文件下载到阿里云虚拟空间里面啊!不想上传啊!2个多g文件这得下载和上传到什么时候去,以前有这个php文件,好久没用虚拟空间不知道弄在哪里去了
广西网友:代码网上一抓一大把,自己随便改改就能用。
不过2个g还是别指望php了,下一会就超时了,还是ftp慢慢传吧
云南网友:在目标空间做个上传接收,然后在zip机器用命令行curl 直接POST @file上传?
台湾网友:只能用国内vps下载本地再上传了。
河南网友:
谷歌搜索找了个自己改下代码,大家需要就拿去吧
- <?php
- if (isset($_POST[‘url’]) and !empty($_POST[‘url’])) {
- set_time_limit (0);
- function microtime_float() {
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$usec + (float)$sec);
- }
- function RealSize($size) {
- if ($size < 1024) return $size . ‘ Byte’;
- if ($size < 1048576) return round($size / 1024, 2) . ‘ KB’;
- if ($size < 1073741824) return round($size / 1048576, 2) . ‘ MB’;
- if ($size < 1099511627776) return round($size / 1073741824, 2) . ‘ GB’;
- }
- function wrjs() {
- global $current, $total, $size, $time, $inittime, $temptime, $initsize;
- $k = "";
- $per = round(($current / $total) * 100);
- $temptime2 = microtime_float();
- if ($per == 100 || ($temptime2 – $temptime > 1)) {
- $speed = $current / ($temptime2 – $inittime);
- $formatespeed = RealSize($speed) . ‘/s’;
- $formatetotal = RealSize($total);
- $formatecurrent = RealSize($current);
- $pasttime = ‘已用时:’ . round($temptime2 – $inittime) . ‘秒’;
- $lasttime = ‘ 估计还要:’ . round(($total – $current) / $speed) . ‘秒’;
- $str = $per . ‘|’ .$formatespeed.’|’. $pasttime . $lasttime . ‘|’ . $formatecurrent . ‘|’ . $formatetotal;
- @file_put_contents(‘downinfo.txt’, $str);
- $temptime = $temptime2;
- $initsize = $current;
- }
- }
- $destination_folder = ‘./’;
- $url = $_POST[‘url’];
- $info = get_headers($url, 1);
- $total = $info[‘Content-Length’];
- $current = 0;
- $newfname = $destination_folder . basename($url);
- $file = fopen ($url, "rb");
- $inittime = $temptime = microtime_float();
- $initsize = 0;
- if ($file) {
- $newf = fopen ($newfname, "wb");
- if ($newf)
- while (!feof($file)) {
- $str = fread($file, 1024 * 8);
- $current += strlen($str);
- fwrite($newf, $str, 1024 * 8);
- wrjs();
- }
- echo ‘<center>下载完毕,共计用时:’ . round(microtime_float() – $inittime) . ‘秒</center>’;
- }
- if ($file) {
- fclose($file);
- }
- if ($newf) {
- fclose($newf);
- }
- exit;
- }
- if (isset($_GET[‘getinfo’])) {
- $arr = file_get_contents(‘downinfo.txt’);
- if ($arr) {
- header("Content-type: text/html; charset=utf-8");
- echo $arr;
- }
- exit;
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>远程下载</title>
- <style>
- *{font-size:12px;}
- .bar1 {background: url("/images/progress_bar_null.gif"); position:relative; text-align:left; height:13px; width:540px; border:1px solid #505050;margin:0 auto;}
- .bar2 {background: url("/images/progress_bar.gif"); position:relative; text-align:left; height:13px; width:0%;}
- .info{width:540px;margin:20px auto;font-size:12px;}
- </style>
- <script type="text/javascript">
- <!–
- var isstart=false;
- function check() {
- if (g(‘downurl’).value=="") {
- alert(‘为空不能提交’);
- return false;
- }
- setTimeout("startdown()",2000);
- return true;
- }
- function frameload() {
- if (isstart) {
- downfinish();
- }
- }
- function downfinish() {
- isstart=false;
- clearInterval(timename);
- }
- function startdown() {
- g(‘downinfo’).style.display="block";
- isstart=true;
- timename=setInterval("getinfo();",500);
- }
- function resetinfo(p,s,t,c,tl) {
- g(‘down_status’).style.width=p+"%";
- g(‘speed’).innerHTML=’平均速率:’+s;
- g(‘time’).innerHTML=’时间信息:’+t;
- g(‘current’).innerHTML=’已下载:’+c;
- g(‘total’).innerHTML=’文件大小:’+tl;
- if (p==100) {
- clearInterval(timename);
- }
- }
- function getinfo() {
- if (isstart) {
- ajax({
- url: "<?php echo basename(__FILE__);?>?getinfo="+Math.random(),
- data: "is=ajax" ,
- success: function (responseText) {
- arr=responseText.split(‘|’);
- if (arr.length==5) {
- resetinfo(arr[0],arr[1],arr[2],arr[3],arr[4]);
- } else {
- alert(responseText);
- }
- }
- });
- }
- else {
- clearInterval(timename);
- }
- }
- function ajax(s) {
- var a = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
- with(a) {
- open("POST", s.url, true);
- setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
- send(s.data);
- onreadystatechange = function () {
- readyState == 4 && status == 200 ? s.success(responseText) : null
- }
- }
- };
- function g(ob) {
- return document.getElementById(ob);
- }
- //–>
- </script>
- </head>
- <body>
- <center><form method="post" id="urlform" target="downframe" onsubmit="return check();">
- <div style="display:none;"><iframe name="downframe" src="about:blank"></iframe></div>
- <input name="url" id=’downurl’ size="50" />
- <input name="submit" value="提交下载地址" type="submit" />
- </form></center>
- <div id="downinfo" style="margin-top:30px;display:none;">
- <div class="bar1" id="upload_status_wrap" align="center">
- <div class="bar2" id="down_status"></div>
- </div>
- <div class="info">
- <div id="speed"> </div>
- <div id="time"> </div>
- <div id="current"> </div>
- <div id="total"> </div>
- </div>
- </div>
- <script language="javascript">
- </script>
- </body>
- </html>
复制代码
重庆网友:
谷歌搜索找了个自己改下代码,大家需要就拿去吧
- <?php
- if (isset($_POST[‘url’]) and !empty($_POST[‘url’])) {
- set_time_limit (0);
- function microtime_float() {
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$usec + (float)$sec);
- }
- function RealSize($size) {
- if ($size < 1024) return $size . ‘ Byte’;
- if ($size < 1048576) return round($size / 1024, 2) . ‘ KB’;
- if ($size < 1073741824) return round($size / 1048576, 2) . ‘ MB’;
- if ($size < 1099511627776) return round($size / 1073741824, 2) . ‘ GB’;
- }
- function wrjs() {
- global $current, $total, $size, $time, $inittime, $temptime, $initsize;
- $k = "";
- $per = round(($current / $total) * 100);
- $temptime2 = microtime_float();
- if ($per == 100 || ($temptime2 – $temptime > 1)) {
- $speed = $current / ($temptime2 – $inittime);
- $formatespeed = RealSize($speed) . ‘/s’;
- $formatetotal = RealSize($total);
- $formatecurrent = RealSize($current);
- $pasttime = ‘已用时:’ . round($temptime2 – $inittime) . ‘秒’;
- $lasttime = ‘ 估计还要:’ . round(($total – $current) / $speed) . ‘秒’;
- $str = $per . ‘|’ .$formatespeed.’|’. $pasttime . $lasttime . ‘|’ . $formatecurrent . ‘|’ . $formatetotal;
- @file_put_contents(‘downinfo.txt’, $str);
- $temptime = $temptime2;
- $initsize = $current;
- }
- }
- $destination_folder = ‘./’;
- $url = $_POST[‘url’];
- $info = get_headers($url, 1);
- $total = $info[‘Content-Length’];
- $current = 0;
- $newfname = $destination_folder . basename($url);
- $file = fopen ($url, "rb");
- $inittime = $temptime = microtime_float();
- $initsize = 0;
- if ($file) {
- $newf = fopen ($newfname, "wb");
- if ($newf)
- while (!feof($file)) {
- $str = fread($file, 1024 * 8);
- $current += strlen($str);
- fwrite($newf, $str, 1024 * 8);
- wrjs();
- }
- echo ‘<center>下载完毕,共计用时:’ . round(microtime_float() – $inittime) . ‘秒</center>’;
- }
- if ($file) {
- fclose($file);
- }
- if ($newf) {
- fclose($newf);
- }
- exit;
- }
- if (isset($_GET[‘getinfo’])) {
- $arr = file_get_contents(‘downinfo.txt’);
- if ($arr) {
- header("Content-type: text/html; charset=utf-8");
- echo $arr;
- }
- exit;
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>远程下载</title>
- <style>
- *{font-size:12px;}
- .bar1 {background: url("/images/progress_bar_null.gif"); position:relative; text-align:left; height:13px; width:540px; border:1px solid #505050;margin:0 auto;}
- .bar2 {background: url("/images/progress_bar.gif"); position:relative; text-align:left; height:13px; width:0%;}
- .info{width:540px;margin:20px auto;font-size:12px;}
- </style>
- <script type="text/javascript">
- <!–
- var isstart=false;
- function check() {
- if (g(‘downurl’).value=="") {
- alert(‘为空不能提交’);
- return false;
- }
- setTimeout("startdown()",2000);
- return true;
- }
- function frameload() {
- if (isstart) {
- downfinish();
- }
- }
- function downfinish() {
- isstart=false;
- clearInterval(timename);
- }
- function startdown() {
- g(‘downinfo’).style.display="block";
- isstart=true;
- timename=setInterval("getinfo();",500);
- }
- function resetinfo(p,s,t,c,tl) {
- g(‘down_status’).style.width=p+"%";
- g(‘speed’).innerHTML=’平均速率:’+s;
- g(‘time’).innerHTML=’时间信息:’+t;
- g(‘current’).innerHTML=’已下载:’+c;
- g(‘total’).innerHTML=’文件大小:’+tl;
- if (p==100) {
- clearInterval(timename);
- }
- }
- function getinfo() {
- if (isstart) {
- ajax({
- url: "<?php echo basename(__FILE__);?>?getinfo="+Math.random(),
- data: "is=ajax" ,
- success: function (responseText) {
- arr=responseText.split(‘|’);
- if (arr.length==5) {
- resetinfo(arr[0],arr[1],arr[2],arr[3],arr[4]);
- } else {
- alert(responseText);
- }
- }
- });
- }
- else {
- clearInterval(timename);
- }
- }
- function ajax(s) {
- var a = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
- with(a) {
- open("POST", s.url, true);
- setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
- send(s.data);
- onreadystatechange = function () {
- readyState == 4 && status == 200 ? s.success(responseText) : null
- }
- }
- };
- function g(ob) {
- return document.getElementById(ob);
- }
- //–>
- </script>
- </head>
- <body>
- <center><form method="post" id="urlform" target="downframe" onsubmit="return check();">
- <div style="display:none;"><iframe name="downframe" src="about:blank"></iframe></div>
- <input name="url" id=’downurl’ size="50" />
- <input name="submit" value="提交下载地址" type="submit" />
- </form></center>
- <div id="downinfo" style="margin-top:30px;display:none;">
- <div class="bar1" id="upload_status_wrap" align="center">
- <div class="bar2" id="down_status"></div>
- </div>
- <div class="info">
- <div id="speed"> </div>
- <div id="time"> </div>
- <div id="current"> </div>
- <div id="total"> </div>
- </div>
- </div>
- <script language="javascript">
- </script>
- </body>
- </html>
复制代码
未经允许不得转载:美国VPS_搬瓦工CN2 GIA VPS » 大家有没有php下载zip文件的代码