Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lahore, Pakistan
    Posts
    150
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How To Make Directory

    Hi,

    I am making a directory by using a builtin PHP function "mkdir".

    i am using this code:

    mkdir("txt");

    But how can i check that, is this directory is already created or not.If this directory is already created then it just shows a message "directory already created", and otherwise it will create this directory.

    Kindly help me that how can i write this code.

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Something like this:

    PHP Code:
    $dir 'directory_name';
    $path '/path/to/directory/';

    if(
    file_exists($path $dir) && is_dir($path $dir)) {
        echo 
    'Sorry, a directory with that name already exists.';
    } else {
        
    // your code to create the directory



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •