频道栏目
首页 > 资讯 > 文件处理 > 正文

PHP判断文件是否存在、是否可读、目录是否存在的代码

16-01-06        来源:[db:作者]  
收藏   我要投稿

1、is_readable() 函数判断指定文件名是否可读.
指定的文件或目录存在并且可读,则返回 TRUE

<?php
$file = a.php';
if (is_readable($file) == false) {
die('文件不存在或者无法读取');
} else {
echo '存在';
}
?>

2、file_exists -- 检查文件或目录是否存在
说明
bool file_exists ( string filename )
如果由 filename 指定的文件或目录存在则返回 TRUE,否则返回 FALSE.

<?php
$filename = a.php';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>

3、is_file -- 判断给定文件名是否为一个正常的文件
说明
bool is_file ( string filename)
如果文件存在且为正常的文件则返回 TRUE.

<?php
$file = ‘a.php';
if (is_file($file) == false) {
die('文件不存在或者无法读取');
} else {
echo '存在';
}
?>

相关TAG标签
上一篇:PHP中删除目录的三种方法
下一篇:php文件大小单位换算
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站