How does PHP determine whether it is a folder or a file?

Guanhui
Release: 2023-03-03 12:34:02
Original
3278 people have browsed it

How does PHP determine whether it is a folder or a file?

#How does PHP determine whether it is a folder or a file?

1. Use the "is_file()" function to determine whether it is a file. If it is a file, the return result is true, otherwise it is false;

Usage example

<?php
var_dump(is_file(&#39;a_file.txt&#39;)) . "\n";
var_dump(is_file(&#39;/usr/bin/&#39;)) . "\n";
?>
Copy after login

Result

bool(true)
bool(false)
Copy after login

2. Use the "is_dir()" function to determine whether it is a directory, and the return result is true or false.

Usage example

<?php
var_dump(is_dir(&#39;a_file.txt&#39;));
var_dump(is_dir(&#39;bogus_dir/abc&#39;));

var_dump(is_dir(&#39;..&#39;)); //one dir up
?>
Copy after login

Result

bool(false)
bool(false)
bool(true)
Copy after login

Recommended tutorial: "PHP"

The above is the detailed content of How does PHP determine whether it is a folder or a file?. 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