PHP function to determine whether it is a directory

(*-*)浩
Release: 2023-02-24 15:20:01
Original
2721 people have browsed it

PHP function to determine whether it is a directory

php is_dir() function introduction

is_dir — Determine whether the given file name is a directory

Syntax: (Recommended learning: PHP Programming from entry to proficiency)

bool is_dir ( string $filename )
Copy after login

Determine whether the given file name is a directory.

Parameters:

filename Returns TRUE if the file name exists and is a directory. If filename is a relative path, its relative path is checked against the current working directory.

Return value:

If the file name exists and is a directory, return TRUE, otherwise return FALSE.

php is_dir() example

/**
 * 判断 文件/目录 是否可写(取代系统自带的 is_writeable 函数)
 *
 * @param string $file 文件/目录
 * @return boolean
 */
function new_is_writeable($file) {
    if (is_dir($file)){
        $dir = $file;
        if ($fp = @fopen("$dir/test.txt", 'w')) {
            @fclose($fp);
            @unlink("$dir/test.txt");
            $writeable = 1;
        } else {
            $writeable = 0;
        }
    } else {
        if ($fp = @fopen($file, 'a+')) {
            @fclose($fp);
            $writeable = 1;
        } else {
            $writeable = 0;
        }
    }
 
    return $writeable;
}
Copy after login

The above is the detailed content of PHP function to determine whether it is a directory. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template