Home >Backend Development >PHP Problem >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('a_file.txt')) . "\n"; var_dump(is_file('/usr/bin/')) . "\n"; ?>
Result
bool(true) bool(false)
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('a_file.txt')); var_dump(is_dir('bogus_dir/abc')); var_dump(is_dir('..')); //one dir up ?>
Result
bool(false) bool(false) bool(true)
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!