本文翻译自:How do I check if a directory exists? “is_dir”, “file_exists” or both?
I want to create a directory if it does'nt exist already. 如果目录尚不存在,我想创建一个目录。
Is using is_dir
enough for that purpose? 使用is_dir
是否足以达到目的?
if ( !is_dir( $dir ) ) {
mkdir( $dir );
}
Or should I combine is_dir
with file_exists
? 还是应该将is_dir
与file_exists
结合使用?
if ( !file_exists( $dir ) && !is_dir( $dir ) ) {
mkdir( $dir );
}
#1楼
参考:https://stackoom.com/question/MlWN/如何检查目录是否存在-is-dir-file-exists-还是两者
#2楼
$year = date("Y");
$month = date("m");
$filename = "../".$year;
$filename2 = "../".$year."/".$month;
if(file_exists($filename)){
if(file_exists($filename2)==false){