How to check a folder doesn’t already exist using php

0

In this tutorial we will create a new folder using mkdir command and check if condition folder exist and not exist using is_dir command below code available so check. You may also like How to Copy file from one folder to another folder using PHP and How to create new folder using php.

PHP Code

$candidate_id = 1;
if (! is_dir ( './public/images/candidate/'.$candidate_id )) {
    mkdir ( './public/images/candidate/'.$candidate_id, 0777, true );
}
if (! is_dir ( './public/images/candidate/'.$candidate_id.'/candidate_photo' )) {
        mkdir ( './public/images/candidate/'.$candidate_id.'/candidate_photo', 0777, true );
}