Access our premium support and let us know your problems, we will help you solve them.

0
No products in the cart.

Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: Create a folder if it doesn't already exist #10803
    blankaditya-malviya
    Participant

    We should always modularise our code and I’ve written the same check it below…

    We first check the directory. If the directory is absent, we create the directory.

    $boolDirPresents = $this->CheckDir($DirectoryName);
    
    if (!$boolDirPresents) {
            $boolCreateDirectory = $this->CreateDirectory($DirectoryName);
            if ($boolCreateDirectory) {
            echo "Created successfully";
          }
      }
    
    function CheckDir($DirName) {
        if (file_exists($DirName)) {
            echo "Dir Exists<br>";
            return true;
        } else {
            echo "Dir Not Absent<br>";
            return false;
        }
    }
         
    function CreateDirectory($DirName) {
        if (mkdir($DirName, 0777)) {
            return true;
        } else {
            return false;
        }
    }
    
Viewing 1 post (of 1 total)