腾讯云618限量抢购
  1. PHP+MySQL数据库教程
  2. PHP进阶教程
  3. ThinkPHP 3.0/3.1 教程

PHP 取得文件大小、类型、修改时间等信息

最后更新:2010-10-26 21:27阅读:33805

目录

filesize()

filesize() 函数用于取得文件大小,成功返回文件大小的字节数,否则返回 FALSE 。

语法:

int filesize( string filename )

例子:

<?php
$filename = 'test.txt';
echo $filename.'文件大小为: '.filesize($filename).' bytes';
?>

提示

filesize() 函数在碰到大于 2GB 的文件时可能会返回非预期的结果。对于 2GB 到 4GB 之间的文件通常可以使用 sprintf("%u", filesize($file)) 来克服此问题。

filetype()

filetype() 函数用于取得文件类型,成功返回返回文件的类型,可能的值有 fifo,char,dir,block,link,file 和 unknown 。错误则返回 FALSE 。

语法:

string filetype( string filename )

例子:

<?php
$filename = 'test.txt';
echo filetype($filename);    //输出 file
?>

filemtime()

filemtime() 函数用于检查文件修改时间,成功返回文件上次被修改的时间戳,否则返回 FALSE。

语法:

int filemtime( string filename )

例子:

<?php
$filename = "test.txt";
echo "$filename 修改日期为:",date("Y-m-d H:i:s",filemtime($filename));
?>

运行例子输出:

test.txt 修改日期为:2010-12-31 23:30:22

参考阅读:

PHP 时间戳 timestamp

PHP date 函数格式化时间


本章节内容共分 11 部分:
  1. 1. PHP 文件处理
  2. 2. PHP file_put_contents 函数:将字符串写入或追加到文件
  3. 3. PHP 取得文件大小、类型、修改时间等信息
  4. 4. PHP 文件创建与打开 fopen 函数
  5. 5. PHP 文件读取 fread、fgets、fgetc、file_get_contents 与 file 函数
  6. 6. PHP 检查文件是否存在 file_exists 函数
  7. 7. PHP 检查文件能否读写执行 is_readable、is_writable 与 is_executable 函数
  8. 8. PHP 文件拷贝 copy 函数
  9. 9. PHP 文件删除 unlink 函数
  10. 10. PHP 文件指针函数
  11. 11. PHP fwrite 函数:将字符串写入文件(追加与换行)
腾讯云618限量抢购