dirfill.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. require_once('include/config.php');
  3. require_once('include/db.php');
  4. $isnew = @$_POST['isnew'];
  5. $dirpath = @$_POST['path'];
  6. if (empty($dirpath))
  7. die('Invalid request');
  8. if ($isnew == 'true') {
  9. create_db_dir($dirpath, $_POST['name'], $_POST['comment'], $_POST['tags'], $_POST['date']);
  10. } else {
  11. update_db_dir($dirpath, $_POST['name'], $_POST['comment'], $_POST['tags'], $_POST['date']);
  12. }
  13. $dirid = get_dir_info($dirpath)['id'];
  14. $images = get_dir_images($dirpath);
  15. $path = $config['basedir'].$dirpath.'/';
  16. $dir_handle = @opendir($path) or die('Directory open error');
  17. $i=0;
  18. $files = [];
  19. while ($file = readdir($dir_handle)) {
  20. if(is_dir($file))
  21. continue;
  22. $files[] = array('name' => $file, 'date' => filemtime($path.$file));
  23. }
  24. closedir($dir_handle);
  25. foreach($files as $file) {
  26. if (image_in_dir($file['name'], $images))
  27. continue;
  28. add_db_image($dirid, '', '', '', $file['name'], $file['date']);
  29. }
  30. $count = get_dir_count($dirpath);
  31. update_dir_count($dirpath, $count);
  32. function image_in_dir($path, $images) {
  33. foreach($images as $image) {
  34. if ($image['path'] == $path)
  35. return true;
  36. }
  37. return false;
  38. }
  39. ?>DONE