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

PHP 检查文件是否存在 file_exists 函数

最后更新:2011-01-01 00:00阅读:12575

file_exists() 函数用于检查一个文件或目录是否存在。

file_exists()

file_exists() 函数检查文件或目录是否存在,成功返回 TRUE,否则返回 FALSE 。

语法:

bool file_exists( string filename )

例子:

<?php
$filename = 'test.txt';
if (file_exists($filename)) {
    echo "文件 $filename 存在";
} else {
    echo "文件 $filename 不存在";
}
?>

本章节内容共分 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限量抢购