John
John

Reputation: 2501

how to create month->day upload path directories when processing upload submit

what is the simple way to create folders and sub-folders as upload path? based on witch day it is example:

-files
 -2012 //year
   -01 //month
     +01 //day
     +02
     +03
     .
     .
     .
     +29
     +30
   +02 //month
   +03
   +04
   +05
   +06
   +07
 +2013
 .
 .
 .

is there any class or function to do this making directories?

Upvotes: 1

Views: 491

Answers (2)

Mihai Stancu
Mihai Stancu

Reputation: 16107

$base_dir = '/path/to/your/dir';
$new_dir = $base_dir.date('/Y/m/d/');
if(!file_exists($new_dir) AND is_writable($base_dir)) {
    mkdir($new_dir, 0755, true)
}

Upvotes: 3

eric.itzhak
eric.itzhak

Reputation: 16062

You can use mkdir(). It has an option to create folders recursively.

Then just build a path using your desired date, and be sure to add true to the function.

Meaning something like :

mkdir("/2012/5/25", 0755, true);

To build your date path you need to use the PHP method date(), for further reading and examples read the documentation.

Upvotes: 3

Related Questions