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

How to determine if it is a folder in php

青灯夜游
青灯夜游Original
2021-11-01 18:05:191836browse

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)
  • 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 不是文件夹");
}
?>

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!

Statement:
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