Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php判断是否为文件(is_file())或目录(is_dir())的实例代码

php判断是否为文件(is_file())或目录(is_dir())的实例代码

发布时间:2017-01-17   编辑:www.jquerycn.cn
分享二个php实例代码,学习使用php检测是否为文件、是否为目录的方法,学习下is_file()、is_dir()的用法。有需要的朋友研究下。

1,php检测变量是否为一个文件,is_file()的用法举例。
 

复制代码 代码示例:
<html>
<head>
<title>is_file()判断是否为文件-www.jbxue.com</title>
</head>
<body>
<?php
$file = "test.txt";
outputFileTestInfo( $file );
function outputFileTestInfo( $f ){
   if ( ! file_exists( $f ) ){
       print "$f does not exist<BR>";
      return;
   }
   print "$f is ".(is_file( $f )?"":"not ")."a file<br>";
}
?>
</body>
</html>

2,php检测是否为一个目录,is_dir()的用法举例。
 

复制代码 代码示例:
<html>
<head>
<title>is_dir()检测是否为一个目录-www.jbxue.com</title>
</head>
<body>
<?php
$file = "test.txt";
outputFileTestInfo( $file );
function outputFileTestInfo( $f ){
   if ( ! file_exists( $f ) ){
       print "$f does not exist<BR>";
      return;
   }
   print "$f is ".(is_dir( $f )?"":"not ")."a directory<br>";
}
?>
</body>
</html>

您可能感兴趣的文章:
php判断是否为文件(is_file())或目录(is_dir())的实例代码
file_exists与is_file、is_dir的区别
php file_exists is_file与is_dir函数的区别分析
php中is_file与file_exists的区别
php 判断文件存在与否的函数选择(file_exists or is_file)
PHP中file_exists与is_file,is_dir的区别
PHP is_file、file_exists、is_dir总结
php中is_file和file_exists与is_dir的区别
判断对文件空目录是否有读写权限的php代码
php用于判断文件是否存在、是否可读、目录是否存在的代码

关键词: is_file   
[关闭]