What function can be used to check if a file is a directory in PHP?
To check if a file is a directory in PHP, you can use the is_dir() function. This function takes a file path as an argument and returns true if the file is a directory, and false otherwise. You can use this function to determine if a specific file is a directory before performing any operations on it.
$file_path = 'path/to/file/or/directory';
if (is_dir($file_path)) {
echo "The file is a directory.";
} else {
echo "The file is not a directory.";
}
Related Questions
- How can PHP be used to differentiate between user input options in a search form and generate appropriate SQL queries?
- How does changing the server environment, such as switching to WAMP, impact PHP include paths and file references?
- How can PHP be used to iterate through JSON arrays to display images based on the data?