Cron.php 989 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Upload\Lib;
  3. use Dever;
  4. class Cron
  5. {
  6. public function import_api()
  7. {
  8. }
  9. # 将本地图片导入到数据库中
  10. public function import()
  11. {
  12. $path = Dever::data() . 'pic/';
  13. $dir = scandir($path);
  14. if ($dir) {
  15. foreach ($dir as $k => $v) {
  16. if ($v != '.' && $v != '..') {
  17. $catePath = $path . $v . '/';
  18. if (is_dir($catePath)) {
  19. $cate = $this->createCate($v);
  20. $this->load($catePath, $cate);
  21. }
  22. }
  23. }
  24. }
  25. }
  26. private function createCate($name)
  27. {
  28. $where['name'] = $name;
  29. $cate = Dever::db('upload/cate')->one($where);
  30. if (!$cate) {
  31. $cate['id'] = Dever::db('upload/cate')->insert($where);
  32. }
  33. return $cate['id'];
  34. }
  35. private function load($path, $cate)
  36. {
  37. $dir = scandir($path);
  38. if ($dir) {
  39. foreach ($dir as $k => $v) {
  40. if ($v != '.' && $v != '..') {
  41. $cate = $this->createCate($v);
  42. $this->load($path . $v . '/', $cate);
  43. }
  44. }
  45. }
  46. }
  47. }