LMSouq
general-dev Open

How do I check if a directory exists? "is_dir", "file_exists" or both?

PE
Peter
1 month ago
3 views
Problem Description
I want to create a directory if it does not exist already. Is using the `is_dir` function enough for that purpose? if ( !is_dir( $dir ) ) { mkdir( $dir ); } Or should I combine `is_dir` with `file_exists`? if ( !file_exists( $dir ) && !is_dir( $dir ) ) { mkdir( $dir ); }

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base