這篇文章主要介紹了php獲得檔案大小和檔案創建時間的方法,涉及php中filesize及fileatime函數的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了php獲得文件大小和文件創建時間的方法。具體分析如下:
php中可以顯示檔案的各種屬性,這些屬性包括檔案的最後存取時間、最後修改時間、檔案大小等。
<HTML> <HEAD> <TITLE>Returning information about a file</TITLE> </HEAD> <BODY> <?php print "The size of the file is "; print filesize( "samplefile.doc" ); print "<br>"; $atime = fileatime( "samplefile.doc" ); print "This file accessed on "; print date("l, M d, Y g:i a", $atime); print "<br>"; $mtime = filemtime( "samplefile.doc" ); print "This file was modified on "; print date("l, M d, Y g:i a", $mtime); print "<br>"; $ctime = filectime( "samplefile.doc" ); print "This file was changed on "; print date("l, M d, Y g:i a", $ctime); ?> </BODY> </HTML>
filemtime ( string filename )
#傳回檔案上次被修改的時間,出錯時傳回 FALSE。時間以 Unix 時間戳記的方式傳回,可用於 date()。
filectime ( string filename )
傳回檔案上次 inode 被修改的時間,如果出錯則傳回 FALSE。時間以 Unix 時間戳記的方式返回。
fileatime ( string filename )
傳回檔案上次被存取的時間,如果發生錯誤則回傳 FALSE。時間以 Unix 時間戳記的方式返回。
////////////////////////////
filectime:linux最後一次修改時間
filemtime:最後一次修改時間
fileatime:最後一次造訪的時間
///////////////////////////// /////////////////////////////////////////////////
filemtime
(PHP 3, PHP 4 )
filemtime -- 取得檔案修改時間
說明
int filemtime ( string filename)
傳回檔案上次被修改的時間,出錯時回傳FALSE。時間以 Unix 時間戳記的方式傳回,可用於 date()。
註: 本函數的結果會被快取。詳細資訊請參閱 clearstatcache()。
註: 本函數不能作用於遠端文件,被檢查的文件必須透過伺服器的文件系統存取。
本函數傳回檔案中的資料區塊上次被寫入的時間,也就是說,檔案的內容上次被修改的時間。
範例1. filemtime() 範例
<?php // outputs e.g. somefile.txt was last modified: December 29 2002 22:16:23. $filename = 'somefile.txt'; if (file_exists($filename)) { echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename)); } ?>
filectime
(PHP 3, PHP 4 )
filectime -- 取得檔案的inode 修改時間
說明
int filectime ( string filename)
傳回檔案上次inode 被修改的時間,如果出錯則回傳FALSE。時間以 Unix 時間戳記的方式返回。
注意:在大多數 Unix 檔案系統中,當一個檔案的 inode 資料被改變時則該檔案被認為是修改了。也就是說,當檔案的權限,擁有者,所有群組或其它 inode 中的元資料被更新時。參見 filemtime()(這就是你想用於在 web 頁面中建立「最後更新時間」腳註的函數)和 fileatime()。
注意某些 Unix 說明文字中把 ctime 說成是該檔案建立的時間,這是錯的。在大多數 Unix 檔案系統中沒有 Unix 檔案的建立時間。
註: 本函數的結果會被快取。詳細資訊請參閱 clearstatcache()。
註: 本函數不能作用於遠端文件,被檢查的文件必須透過伺服器的文件系統存取。
範例1. fileatime() 範例
<?php // 输出类似:somefile.txt was last changed: December 29 2002 22:16:23. $filename = 'somefile.txt'; if (file_exists($filename)) { echo "$filename was last changed: " . date ("F d Y H:i:s.", filectime($filename)); } ?>
fileatime
(PHP 3, PHP 4 )
fileatime -- 取得檔案的上次存取時間
說明
int fileatime ( string filename)
#傳回檔案上次被存取的時間,如果發生錯誤則回傳FALSE。時間以 Unix 時間戳記的方式返回。
注意:一個檔案的 atime 應該在不論何時讀取了此檔案中的資料區塊時被更改。當一個應用程式定期存取大量文件或目錄時很影響效能。有些 Unix 檔案系統可以在載入時關閉 atime 的更新以提高這類程式的效能。 USENET 新聞群組假脫機就是一個常見的例子。在這種檔案系統下本函數沒有用處。
註: 本函數的結果會被快取。詳細資訊請參閱 clearstatcache()。
註: 本函數不能作用於遠端文件,被檢查的文件必須透過伺服器的文件系統存取。
範例 1. fileatime() 範例
<?php // 输出类似:somefile.txt was last accessed: December 29 2002 22:16:23. $filename = 'somefile.txt'; if (file_exists($filename)) { echo "$filename was last accessed: " . date ("F d Y H:i:s.", fileatime($filename)); } ?>
總結:以上就是這篇文章的全部內容,希望能對大家的學習有所幫助。
相關推薦:
以上是簡述php取得檔案大小與創建時間的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

你應該關心DependencyInjection(DI),因為它能讓你的代碼更清晰、更易維護。 1)DI通過解耦類,使其更模塊化,2)提高了測試的便捷性和代碼的靈活性,3)使用DI容器可以管理複雜的依賴關係,但要注意性能影響和循環依賴問題,4)最佳實踐是依賴於抽象接口,實現鬆散耦合。

是的,優化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)優化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,並避免使用

theKeyStrategiestosigantificallyBoostPhpaPplicationPerformenCeare:1)UseOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)優化AtabaseInteractionswithPreparedStateTementStatementStatementAndProperIndexing,3)配置

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)


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

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

熱門文章

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3漢化版
中文版,非常好用

Dreamweaver CS6
視覺化網頁開發工具

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

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)