PHP Creating directories - WordPress File Uploads style - Year / Month
<?php
$year=date('Y');
$month=date('m');
$directoryPath = "{$year}/{$month}";
// First check if directory already exists
if(!file_exists($directoryPath)){
mkdir($directoryPath,0777,TRUE);
exit("{$directoryPath} created");
}
exit("{$directoryPath} exists");
If you run above script , a directory whose name is current month index will be created inside a directory whose name is current full year in the directory where the script is.For example : 2019 / 06