mkdir(); ERROR Urgent help please!

Discussion in 'PHP' started by Dangy, Nov 27, 2009.

  1. #1
    Warning: mkdir() [function.mkdir]: File exists in /home/.../verify.php on line 16
    i
    keep getting that error whats the issue?
    coded used it just

    mkdir('$name',0777);
     $name = ucfirst(strtolower($_POST['username-reg']));
    PHP:
    I need this functionally. I cant have all the folder leading to it 0777 and preferable wouldnt like to use the ftp function.
     
    Dangy, Nov 27, 2009 IP
  2. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #2
    It's giving you an error because the dir already exists.
    There are also a few mistakes in your code. $name shouldn't be in quotes or it will create the dir $name, not the value that $name refers to .. unless you use " instead of '.

    You also need to define $name before you try to create that dir or the var will be empty.

    Try this:
    
    $name = ucfirst(strtolower($_POST['username-reg']));
    if (is_dir($name)) { mkdir($name, 0777); }
     
    PHP:
    You can set the permissions to whatever you want. You don't have to use 0777 when you create the dir.
     
    kbduvall, Nov 27, 2009 IP
  3. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #3
    You may also want to use ucwords() instead of ucfirst() if $name includes a first and last name or else only the first name will be capitalized.
     
    kbduvall, Nov 27, 2009 IP
  4. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #4
    Also on some server configs you have to make the directory at the default setting of 644 and the chmod it to 777 if that is what you must use. I suggest you try 755 first as it is a bit safer.
     
    Colbyt, Nov 27, 2009 IP
  5. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #5
    I second that.
     
    kbduvall, Nov 27, 2009 IP