
原作者BlueStyle 提示 改进地方有
以前的算法是等文件下载完才计算,
现在这个直接在在获取文件时候就计算大小
加了容错语句
增加了判断目录,没有目录自动创建
把计算文件大小的算法换了个
以前的那个光计算文件大小就7行代码,
现在这个只要两行
转载请保留原作者版权信息,由于作者是政府人员,为不惹麻烦,请保留此段文字完整性
html代码:
复制代码 代码如下:
PHP代码:
复制代码 代码如下:
# Copyright 2010 快乐飞扬
# http://www.klfy.org/ 供新手学习参考
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 '
echo '
}elseif(isset($_POST['password'])){
echo '
}
?>

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增強codemodocultion,可驗證性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

選擇DependencyInjection(DI)用於大型應用,ServiceLocator適合小型項目或原型。 1)DI通過構造函數注入依賴,提高代碼的測試性和模塊化。 2)ServiceLocator通過中心註冊獲取服務,方便但可能導致代碼耦合度增加。

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)啟用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替換loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

phpemailvalidation invoLvesthreesteps:1)格式化進行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

tomakephpapplicationsfaster,關注台詞:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

到ImprovephPapplicationspeed,關注台詞:1)啟用opcodeCachingwithapCutoredUcescriptexecutiontime.2)實現databasequerycachingingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandreduceconnection.4 limitesclection.4.4

依赖注入(DI)通过显式传递依赖关系,显著提升了PHP代码的可测试性。1)DI解耦类与具体实现,使测试和维护更灵活。2)三种类型中,构造函数注入明确表达依赖,保持状态一致。3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

WebStorm Mac版
好用的JavaScript開發工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

記事本++7.3.1
好用且免費的程式碼編輯器