| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 | 
							- <?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);
 
- 				}
 
- 			}
 
- 		}
 
- 	}
 
- }
 
 
  |