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 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Folder System PHP

    I'm trying to create a folder system, such that it's logs\year\month\day_hr.txt

    So I got the code to make a year folder and if the year folder exists it doesnt make it (I use the "make year folder" statement to check this).

    However, for the month folder all it displays is "enter month", which means it enters the chkmonth() function but doesn't go through the $files....command.

    I'm fairly new to PHP, so I feel this may be a problem with my use of the date function and mkdir.

    PHP Code:
    function chkyear()
    {
    $files scandir("logs");

    foreach(
    $files as $value)
    if(
    $value==date(Y))
      return 
    TRUE;

    return 
    FALSE;
    }

    function 
    chkmonth()
    {
    echo 
    "enter month\n";
    $files_m $scandir("logs\\".date(Y));
    echo 
    "go through forreach";
    foreach(
    $files as $value)
    {
    if(
    $value==date(M))
    {
        echo 
    "month True";
      return 
    TRUE;
     }

    echo 
    "false month";
    return 
    FALSE;
    }

    function 
    chklog()
    {
    $year date(Y);
    $month date(M);
    $files_l $scandir("logs\\".$year."\\".$month);

    $day date(d);
    $hr date(H);

    foreach(
    $files as $value)
    if(
    $value == $day."_".$hr.".txt")
    return 
    TRUE;

    return 
    FALSE;
    }

    function 
    mklog()
    {

    if(!
    chkyear())
    {
    echo 
    "make year folder";
      
    mkdir("logs\\".date(Y));  
    }
     
     
    if(!
    chkmonth())
    {
        echo 
    "make month folder";
       
    mkdir("logs\\".date(Y)."\\".date(M));
    }

     

    I've played around with, tried different file locations, different params for the date (in terms of month) nothing seems to work. It's already 1:30 and I got to wake up early, so Thanks for the help. I'm sure this is an easy problem.

    Btw I'm on Windows 7 using php 5.2, through apache 2.2

    --Popnbrown

  • #2
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    you're escaping the quotes around the paths unnecessarily

    "logs\\"

    "logs\"

    your app is looking for "logs\\files\\" which would be an invalid path.

  • #3
    New Coder
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by met View Post
    you're escaping the quotes around the paths unnecessarily

    "logs\\"

    "logs\"

    your app is looking for "logs\\files\\" which would be an invalid path.
    Doesn't php require you type backslashes using the escape character since just doing "logs\" is actually the escape character for " while \\ is the escape character for \.

    Got that from http://www.php.net/manual/en/function.mkdir.php#80549

    I also tried using /, still only goes to enter month and then haults. Meaning that something is up with the scandir.

  • #4
    New Coder
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Found the problem
    PHP Code:
    $files_m $scandir("log\\".date(Y)); 

    should be:
    PHP Code:
    $files_m scandir("log\\".date(Y)); 
    Late Night Programming can be painful.


    Thanks for the help anywho, Met.


  •  

    Posting Permissions

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