Checking for and creating directories

Discussion in 'PHP' started by beebe, Jul 26, 2007.

  1. #1
    I am looking for some help in checking if there is a folder, and if the folder is not created it will create it and place the file they uploaded in it.

    So for example, user "Don" logs in. He uploads a file to his folder and creates his folder unless it has already been created.
     
    beebe, Jul 26, 2007 IP
  2. mark84

    mark84 Peon

    Messages:
    56
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use is_dir(string $filename) http://au.php.net/is_dir to check for the directory
    And use mkdir (string $pathname) to create one if needed. http://au.php.net/manual/en/function.mkdir.php
     
    mark84, Jul 26, 2007 IP
  3. beebe

    beebe Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Could you write an example?
     
    beebe, Jul 26, 2007 IP
  4. wmbetts

    wmbetts Peon

    Messages:
    27
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    that's the jest of it.
     
    wmbetts, Jul 26, 2007 IP
  5. mark84

    mark84 Peon

    Messages:
    56
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    //variable holds the username
    $userName = $_POST['username'];
    
    //checking if a directory does NOT exists with his name in the current directory
    //create the directory
    if(!is_dir($userName)))
    {
      mkdir($userName)
    }
    
    //your upload code goes here
    Code (markup):
    Thats the basic idea
     
    mark84, Jul 26, 2007 IP