记住用户名密码
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 条留言 其中:访客:0 条, 博主:0 条