I would like to automatically get the year, month and day. With the following information i would like to create a folder for the daily uploads.
$videoFolder = $_SERVER['DOCUMENT_ROOT']."/Videos/";
if (!empty($_FILES)) {
$date = new DateTime();
$tempFile = $_FILES['file']['tmp_name'];
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$targetFile = $date->getTimestamp() . "." . $extension;
$year = date("Y");
$month = date("M");
$day = date("d");
if (is_dir($videoFolder . $year . "/" . $month . "/" . $day)) {
move_uploaded_file($tempFile, $dayFolder.$targetFile);
print $targetFile;
}
if (!is_dir($videoFolder.$year)) {
mkdir( $videoFolder.$year );
$yearFolder = $videoFolder.$year."/";
if (!is_dir($yearFolder.$month)) {
mkdir($yearFolder. $month);
$monthFolder = $yearFolder . $month . "/";
if (!is_dir($monthFolder . $day)) {
mkdir($monthFolder.$day);
$dayFolder = $monthFolder . $day . "/";
move_uploaded_file($tempFile, $dayFolder.$targetFile);
print $targetFile;
}
}
}
}
EG: Today is 18/Dec/22
So if the folder does not exists create it then place the upload in that directory.
I tested it with the date set as the 23rd and no folder was created.
EG: New Years the code should automatically know and create the folder 2019 with the child folder of Jan then as Jan's child folder as 1. End Dir result; /Videos/2019/Jan/1 then Feb would be /Videos/2019/Feb/1.
It should basically increment itself.