php帶密碼功能并下載遠(yuǎn)程文件保存本地指定目錄 修改加強(qiáng)版
更新時(shí)間:2010年05月16日 23:09:16 作者:
php帶密碼功能并將遠(yuǎn)程文件下載到本地指定目錄修改版,需要的朋友可以參考下。

原作者BlueStyle 提示 改進(jìn)地方有
以前的算法是等文件下載完才計(jì)算,
現(xiàn)在這個(gè)直接在在獲取文件時(shí)候就計(jì)算大小
加了容錯(cuò)語(yǔ)句
增加了判斷目錄,沒有目錄自動(dòng)創(chuàng)建
把計(jì)算文件大小的算法換了個(gè)
以前的那個(gè)光計(jì)算文件大小就7行代碼,
現(xiàn)在這個(gè)只要兩行
轉(zhuǎn)載請(qǐng)保留原作者版權(quán)信息,由于作者是政府人員,為不惹麻煩,請(qǐng)保留此段文字完整性
html代碼:
復(fù)制代碼 代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>快樂飛揚(yáng)博客 - 遠(yuǎn)程文件下載</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代碼:
復(fù)制代碼 代碼如下:
<?php
# Copyright 2010 快樂飛揚(yáng)
# http://www.klfy.org/ 供新手學(xué)習(xí)參考
set_time_limit (0); //不限時(shí) 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/'; // 下載的文件保存目錄。必須以斜杠結(jié)尾
if(!is_dir($destination_folder)) //判斷目錄是否存在
mkdir($destination_folder,0777); //若無則創(chuàng)建,并給與777權(quán)限 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>下載耗時(shí):<font color="blue"> '.$runtime->spent().' </font>微秒,文件大小<font color="blue"> '.$headers["Content-Length"].' </font>字節(jié)</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">密碼錯(cuò)誤!請(qǐng)從新輸入密碼!</font></li>';
}
?>
</body>
</html>
相關(guān)文章
PHP實(shí)現(xiàn)的AES雙向加密解密功能示例【128位】
這篇文章主要介紹了PHP實(shí)現(xiàn)的AES雙向加密解密功能,結(jié)合實(shí)例形式分析了基于AES算法的加密解密類定義與使用技巧,需要的朋友可以參考下2018-09-09PHP 5.3.1 安裝包 VC9 VC6不同版本的區(qū)別是什么
php官網(wǎng)提供了四個(gè)版本,VC9 x86 Non Thread Safe、VC9 x86 Thread Safe、VC6 x86 Non Thread Safe、VC6 x86 Thread Safe,大家看完這篇文章就知道應(yīng)該選擇什么樣的版本了。2010-07-07php設(shè)計(jì)模式 Adapter(適配器模式)
將一個(gè)類的接口轉(zhuǎn)換成客戶希望的另外一個(gè)接口,使用原本不兼容的而不能在一起工作的那些類可以在一起工作2011-06-06php使用mysqli和pdo擴(kuò)展,測(cè)試對(duì)比mysql數(shù)據(jù)庫(kù)的執(zhí)行效率完整示例
這篇文章主要介紹了php使用mysqli和pdo擴(kuò)展,測(cè)試對(duì)比mysql數(shù)據(jù)庫(kù)的執(zhí)行效率,結(jié)合完整實(shí)例形式對(duì)比分析了php分別使用mysqli與pdo進(jìn)行數(shù)據(jù)庫(kù)插入操作的執(zhí)行時(shí)間,需要的朋友可以參考下2019-05-05PHP常用操作類之通信數(shù)據(jù)封裝類的實(shí)現(xiàn)
PHP類的封裝對(duì)于初學(xué)者來說是比較難懂的,下面這篇文章主要給大家介紹了關(guān)于PHP常用操作類之通信數(shù)據(jù)封裝類實(shí)現(xiàn)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編一起來一起學(xué)習(xí)學(xué)習(xí)吧。2017-07-07