Make Directories Error

Discussion in 'PHP' started by Ichigo91, Oct 5, 2007.

  1. #1
    Hi,

    I wrote a script in order to check if a certain directory exist, and it doesn't exist, it should open one.

    $day = date("d");
    $month = date("m");
    $year = date("Y");

    if (!is_dir(files/$year)) {
    mkdir("files/$year",0777); }

    if (!is_dir(files/$year/$month)) {
    mkdir("files/$year/$month",0777); }

    if (!is_dir(files/$year/$month/$day)) {
    mkdir("files/$year/$month/$day",0777); }

    Now, the directories already exist, but every time I try to run the script I get this error:

    Warning: mkdir() [function.mkdir]: File exists in /home/.tristessa/maverick/dbzfan.com/NEW/script.php on line 10

    Warning: mkdir() [function.mkdir]: File exists in /home/.tristessa/maverick/dbzfan.com/NEW/script.php on line 13

    Warning: mkdir() [function.mkdir]: File exists in /home/.tristessa/maverick/dbzfan.com/NEW/script.php on line 16

    Why does it try to create them while they already exist?
    Thanks in advance.
     
    Ichigo91, Oct 5, 2007 IP
  2. chandubhai

    chandubhai Banned

    Messages:
    556
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I am interested. Please PM me.
     
    chandubhai, Oct 5, 2007 IP
  3. theOtherOne

    theOtherOne Well-Known Member

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #3
    hi,

    I think you just forgot some quotes... try it like this:
    
    $day = date("d");
    $month = date("m");
    $year = date("Y");
    
    if (!is_dir("files/$year")) {
    mkdir("files/$year",0777); }
    
    if (!is_dir("files/$year/$month")) {
    mkdir("files/$year/$month",0777); }
    
    if (!is_dir("files/$year/$month/$day")) {
    mkdir("files/$year/$month/$day",0777); }
    
    PHP:
    Did not test it, but it should work now ;)
     
    theOtherOne, Oct 5, 2007 IP
  4. Ichigo91

    Ichigo91 Guest

    Messages:
    948
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks a lot theOtherOne. It works now !:)
     
    Ichigo91, Oct 5, 2007 IP
  5. theOtherOne

    theOtherOne Well-Known Member

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #5
    You're welcome ;) glad I could help
     
    theOtherOne, Oct 5, 2007 IP