dever 4 years ago
parent
commit
d52aaef36c
2 changed files with 58 additions and 0 deletions
  1. 1 0
      config/base.php
  2. 57 0
      lib/Cron.php

+ 1 - 0
config/base.php

@@ -6,6 +6,7 @@ $config['template'] = array
 
 	'assets' => '',
 	'template' => '',
+	'path' => 'html',
 );
 
 return $config;

+ 57 - 0
lib/Cron.php

@@ -0,0 +1,57 @@
+<?php
+namespace Upload\Lib;
+
+use Dever;
+
+class Cron
+{
+	public function import_api()
+	{
+
+	}
+
+	# 将本地图片导入到数据库中
+	public function import()
+	{
+		$path = Dever::data() . 'pic/';
+
+		$dir = scandir($path);
+
+		if ($dir) {
+			foreach ($dir as $k => $v) {
+				if ($v != '.' && $v != '..') {
+					$catePath = $path . $v . '/';
+					if (is_dir($catePath)) {
+						$cate = $this->createCate($v);
+						$this->load($catePath, $cate);
+					}
+				}
+			}
+		}
+	}
+
+	private function createCate($name)
+	{
+		$where['name'] = $name;
+		$cate = Dever::db('upload/cate')->one($where);
+		if (!$cate) {
+			$cate['id'] = Dever::db('upload/cate')->insert($where);
+		}
+
+		return $cate['id'];
+	}
+
+	private function load($path, $cate)
+	{
+		$dir = scandir($path);
+
+		if ($dir) {
+			foreach ($dir as $k => $v) {
+				if ($v != '.' && $v != '..') {
+					$cate = $this->createCate($v);
+					$this->load($path . $v . '/', $cate);
+				}
+			}
+		}
+	}
+}