php带密码功能并下载远程文件保存本地指定目录 修改加强版

全屏阅读
  • 基本信息
  • 作者:
  • 作者已发布:924篇文章
  • 发布时间:2021年04月21日 0:17:52
  • 所属分类:PHP+MySql
  • 阅读次数:1962次阅读
  • 标签:

html代码:

 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>恒富网-远程文件下载</title> 
</head> 
<body > 
<form method="post"> 
<li>File: <input name="url" size="40" /> 
<input name="submit" type="submit" /></li> 
<li>Pass: <input name="password" type="password" /></li> 
</form>

PHP代码:

 
<?php  
set_time_limit (0); //不限时 24 * 60 * 60 
$password = 'admin'; //管理密码 
$pass = $_POST['password']; 
if ($pass == $password) { 
class runtime { 
var $StartTime = 0; 
var $StopTime = 0; 
function get_microtime(){list($usec, $sec) = explode(' ', microtime()); 
return ((float)$usec + (float)$sec);} 
function start() {$this->StartTime = $this->get_microtime();} 
function stop() {$this->StopTime = $this->get_microtime();} 
function spent() { return round(($this->StopTime - $this->StartTime) * 1000, 1);} 
} 
$runtime= new runtime; 
$runtime->start(); 
if (!isset($_POST['submit'])) die(); 
$destination_folder = './Download/'; // 下载的文件保存目录。必须以斜杠结尾 
if(!is_dir($destination_folder)) //判断目录是否存在 
mkdir($destination_folder,0777); //若无则创建,并给与777权限 windows忽略 
$url = $_POST['url']; 
$headers = get_headers($url, 1); //得到文件大小 
if ((!array_key_exists("Content-Length", $headers))) {$filesize=0; } 
$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);} 
$runtime->stop(); 
echo '<br /><li>下载耗时:<font color="blue"> '.$runtime->spent().' </font>微秒,文件大小<font color="blue"> '.$headers["Content-Length"].' </font>字节</li>'; 
echo '<br /><li><font color="red">下载成功! '.$showtime=date("Y-m-d H:i:s").'</font></li>'; 
}elseif(isset($_POST['password'])){ 
echo '<br /><li><font color="red">密码错误!请从新输入密码!</font></li>'; 
} 
?> 
</body> 
</html>

顶一下
(0)
100%
订阅 回复
踩一下
(0)
100%
» 郑重声明:本文由mpxq168发布,所有内容仅代表个人观点。版权归恒富网mpxq168共有,欢迎转载, 但未经作者同意必须保留此段声明,并给出文章连接,否则保留追究法律责任的权利! 如果本文侵犯了您的权益,请留言。

目前有 0 条留言 其中:访客:0 条, 博主:0 条

给我留言

您必须 [ 登录 ] 才能发表留言!