【发布时间】:2018-12-22 16:06:27
【问题描述】:
我想自动获取年月日。有了以下信息,我想为每日上传创建一个文件夹。
$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:今天是 12 月 18 日/22 日
因此,如果该文件夹不存在,请创建它,然后将上传文件放在该目录中。
我测试了它,日期设置为 23 号,没有创建文件夹。
EG:新年代码应该会自动知道并创建文件夹 2019,然后将 Jan 的子文件夹作为 Jan 的子文件夹 1。 结束目录结果; /Videos/2019/Jan/1 然后二月将是 /Videos/2019/Feb/1。
它应该基本上自增。
【问题讨论】:
标签: php