16080891(Lamp→研讨会)
检测文件或者目录是否存在(file_exists)
上一篇 /
下一篇 2007-05-08 20:20:33
/ 个人分类:PHP学习笔记
声明: file_exists(string filename)
如果由filename指定的文件或目录存在则返回True,否则返回False.提示: 在Windows中用//computername/share/filename或者\\computername\share\filename来检查网络中的共享文件.
例:
<?php
$filename = 'hello.txt';
$catalog = 'hello';
//文件检测
if(
file_exists($filename))
{
print $filename."文件存在!<br>";
}else
{
print $filename."文件不存在!<br>";
}
//目录检测
if(
file_exists($catalog)) {
print $catalog."目录存在!";
}else
{
print $catalog."目录不存在!";
}
?>
输出结果:
hello.txt文件不存在!
hello目录存在!
注意: 由于本人已在当前目录下创建了目录"hello",所以执行结果显示该目录存在,而当前目录下没有"hello.txt"文件,因此提示文件不存在.
相关阅读:
- 变量函数 (xile_php, 2007-5-04)
- 函数变量的作用域 (xile_php, 2007-5-04)
- 日期和时间处理(PHP5手册) (xile_php, 2007-5-04)
- 去除多余空格 (xile_php, 2007-5-04)
- 字符串大小写转换函数 (xile_php, 2007-5-04)
- 字符串比较 (xile_php, 2007-5-05)
- 获取指定字符串( substr() ) (xile_php, 2007-5-05)
- 字符串的查找 (xile_php, 2007-5-05)
- 定位字符串 (xile_php, 2007-5-06)
- 字符串替换 (xile_php, 2007-5-06)
导入论坛
收藏
分享给好友
管理
举报
TAG:
PHP学习笔记