...

View Full Version : Folder System PHP



Popnbrown
06-15-2010, 09:05 PM
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.



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

met
06-15-2010, 09:28 PM
you're escaping the quotes around the paths unnecessarily

"logs\\"

"logs\"

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

Popnbrown
06-16-2010, 03:34 AM
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.

Popnbrown
06-16-2010, 03:39 AM
Found the problem


$files_m = $scandir("log\\".date(Y));



should be:


$files_m = scandir("log\\".date(Y));


Late Night Programming can be painful.


Thanks for the help anywho, Met.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum