Home > Backend Development > PHP Problem > How to determine if it is a folder in php

How to determine if it is a folder in php

青灯夜游
Release: 2023-03-13 16:10:01
Original
1962 people have browsed it

In PHP, you can use the is_dir() function to determine whether it is a folder. The function of this function is to check whether the specified file is a directory (folder), the syntax is "is_dir(file)"; if If it is a folder, TRUE is returned.

How to determine if it is a folder in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, you can use the is_dir() function to determine whether it is a folder.

is_dir() function checks whether the specified file is a directory. Syntax:

is_dir(file)
Copy after login
  • file: required parameter, specifies the file to be checked.

If the directory exists, this function returns TRUE.

Example: Determine whether the img file is a folder

How to determine if it is a folder in php

<?php
header("Content-type:text/html;charset=utf-8");
$file = "img";
if(is_dir($file))
{
echo ("$file 是文件夹");
}
else
{
echo ("$file 不是文件夹");
}
?>
Copy after login

Output result:

How to determine if it is a folder in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to determine if it is a folder in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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