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

后端 未结 11 1603
礼貌的吻别
礼貌的吻别 2020-11-28 18:36

I want to create a directory if it does\'nt exist already.

Is using is_dir enough for that purpose?

if ( !is_dir( $dir ) ) {
    mkdir(          


        
11条回答
  •  無奈伤痛
    2020-11-28 19:42

    I had the same doubt, but see the PHP docu:

    https://www.php.net/manual/en/function.file-exists.php

    https://www.php.net/manual/en/function.is-dir.php

    You will see that is_dir() has both properties.

    Return Values is_dir Returns TRUE if the filename exists and is a directory, FALSE otherwise.

提交回复
热议问题