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 );
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…