这篇文章主要介绍了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,并避免使用

theKeyStrategiestosiminificallyBoostphpapplicationPermenCeare:1)useOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)优化AtabaseInteractionswithPreparedStateTemtStatementStatementSandProperIndexing,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
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

WebStorm Mac版
好用的JavaScript开发工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

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

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境