Forum Moderators: coopster

Message Too Old, No Replies

How to create a folder within other folder

         

romzinho2k7

7:04 am on Apr 2, 2006 (gmt 0)

10+ Year Member



Hey

It would like to know how I do to create a folder inside the other of dynamic form. For former:
Year / month / day

I tried to create doing this way:

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

If(!file_exists($year)){
$createsyear = mkdir("$year", 0777);
If(!file_exists($ month)){
$createsmonth = mkdir("$year/$month", 0777);
If(!file_exists($ day)){
$createsday = mkdir("$year/$mês/$dia", 0777);
}
}
}
?>

The problem is that did not work correctly. He only creates if does not have no folder in the server. In case it have a folder he no longer creates the others.

Will it it be what anybody could help to solve that problem?

Thanks

termlimit

7:20 am on Apr 2, 2006 (gmt 0)



try this:
<?php
$year = date("Y");
$month = date("m");
$day = date("d");

If(!file_exists($year)){
$createsyear = mkdir("$year", 0777);
} else {
If(!file_exists($ month)){
$createsmonth = mkdir("$year/$month", 0777);
} else {
If(!file_exists($ day)){
$createsday = mkdir("$year/$mês/$dia", 0777);
} else {
}
}
?>

The other thing is that mkdir needs something to work. Either exec or system.
for example:
exec("mkdir path\to\file")

Try that let me know. Take a look at your error logs also, that can help lead you in the right direction.

romzinho2k7

7:24 pm on Apr 2, 2006 (gmt 0)

10+ Year Member



Does not yet work. He only creates the first folder. To leave then he does not create anymore the folders rest. Does anybody have more some solution?

Thanks

henry0

9:10 pm on Apr 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK done,
your logic was not applied to the second set of "if"
you were missing a final bracket
you combined English with your mother tongue in the last set :)
and you had a space between a few $..and its name value

this works fine
<<<
<?php
$year = date("Y");
$month = date("m");
$day = date("d");
If(!file_exists($year)){
$createsyear = mkdir("$year", 0777);
}
else
{
If(!file_exists("$year/$month")){
$createsmonth = mkdir("$year/$month", 0777);
}
else
{
If(!file_exists($year/$month/$day)){
$createsday = mkdir("$year/$month/$day", 0777);
}
else
{
// whatever
}
}
}
?>