php用于判断文件是否存在、是否可读、目录是否存在的代码
php有很强的文件操作能力,其实用的文件操作函数也不少。
本文为大家介绍几个文件判断的小例子,包括:判断文件是否存在、是否可读、目录是否存在。供初学的朋友参考。
例1:
$file = 'jquerycn.cn.php';
if (is_readable($file) == false) {
die('文件不存在或者无法读取');
} else {
echo '存在';
}
?>
is_readable() 函数判断指定文件名是否可读.
指定的文件或目录存在并且可读,则返回 TRUE
例2:
$filename = 'jquerycn.cn.php';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
file_exists -- 检查文件或目录是否存在
说明
bool file_exists ( string filename )
如果由 filename 指定的文件或目录存在则返回 TRUE,否则返回 FALSE.
例3:
$file = 'jquerycn.cn.php';
if (is_file($file) == false) {
die('文件不存在或者无法读取');
} else {
echo '存在';
}
?>
is_file -- 判断给定文件名是否为一个正常的文件
说明
bool is_file ( string filename)
如果文件存在且为正常的文件则返回 TRUE。
相关阅读:php判断文件是否可读与可写的代码
您可能感兴趣的文章:
php用于判断文件是否存在、是否可读、目录是否存在的代码
使用php判断文件是否存在、是否可读、目录是否存在
php判断文件是否可读与可写的代码
php 读取目录文件夹列表的例子
file_exists与is_file、is_dir的区别
php file_exists is_file与is_dir函数的区别分析
学习linux shell中 if else以及大于、小于、等于逻辑表达式
php检查文件或目录是否存在的代码
检查文件与目录存在与否的php代码
php中is_file与file_exists的区别