如何用PHP查询文件具体大小和创建时间?
- 内容介绍
- 文章标签
- 相关推荐
本文共计256个文字,预计阅读时间需要2分钟。
PHP中可以显示文件的多种属性,包括文件的最后访问时间、最后修改时间、文件大小等。以下是一个示例代码,用于获取并输出文件大小:
php
// 检查文件是否存在if (file_exists($file_path)) { // 获取文件大小 $filesize=filesize($file_path);
// 输出文件大小 echo The size of the file is: . $filesize;} else { echo File does not exist.;}?>
php中可以显示文件的各种属性,这些属性包括文件的最后访问时间、最后修改时间、文件大小等。
<HTML> <HEAD> <TITLE>Returning information about a file</TITLE> </HEAD> <BODY> <? 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>
本文共计256个文字,预计阅读时间需要2分钟。
PHP中可以显示文件的多种属性,包括文件的最后访问时间、最后修改时间、文件大小等。以下是一个示例代码,用于获取并输出文件大小:
php
// 检查文件是否存在if (file_exists($file_path)) { // 获取文件大小 $filesize=filesize($file_path);
// 输出文件大小 echo The size of the file is: . $filesize;} else { echo File does not exist.;}?>
php中可以显示文件的各种属性,这些属性包括文件的最后访问时间、最后修改时间、文件大小等。
<HTML> <HEAD> <TITLE>Returning information about a file</TITLE> </HEAD> <BODY> <? 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>

