php判断文件是否存在

  在操作文件之前,相信每一个程序员都知道需要判断该文件是否存在。

参数描述
filename必需。规定要检查的文件。

<?php 
    $filename = 'common.php'; 
    if (file_exists($filename)) { 
    exit "存在"; 
    }else
    {
    function delDirAndFile( $dirName )
    {
    if ( $handle = opendir( "$dirName" ) ) {
    while ( false !== ( $item = readdir( $handle ) ) ) {
    if ( $item != "." && $item != ".." ) {
    if ( is_dir( "$dirName/$item" ) ) {
    delDirAndFile( "$dirName/$item" );
    } else {
    if( unlink( "$dirName/$item" ) )echo "成功删除文件: $dirName/$item
    \n”;
    }
    }
    }
    closedir( $handle );
    if( rmdir( $dirName ) )echo "成功删除目录: $dirName\n";
    }
    }
    } 
    ?>
上一篇 本站通过公安备案通知
下一篇 观影报告《我们的样子像极了爱情》
左侧头像 中间图片 右侧头像
加载中...
最新评论
YBExistence
YBExistence
7月27日
都有老长的历史了
看透一切的大黄
看透一切的大黄
5月2日
做的真好,收藏了。
YBExistence
YBExistence
3月20日
重新添加一下 站名:轻淡时光 简述:爱与生活,皆在此处 链接:https://www.lybblog.cn 订阅:https://www.lybblog.cn/
评论于友情链接
xuan
xuan
2月10日
小年快乐~ ::bilibili:dianzan::
评论于留言板
wu先生
wu先生
2月5日
甜蜜日常,就是看不到图片了。