lightroom_api.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. session_start();
  3. header('Content-Type: text/html; charset=utf-8');
  4. $zipFolder = "zip/";
  5. $toplevelDir = "pictures/";
  6. $saveFolder = "pictures_save/";
  7. if (!isset($_POST["action"]))
  8. exit("error: no action defined.");
  9. $action = $_POST["action"];
  10. if ($action == "add") {
  11. if (!isset($_POST["file"]))
  12. exit("error: no file specified.");
  13. $file = $_POST["file"];
  14. if (!file_exists($file))
  15. exit("error: file does not exist.".$file);
  16. $files = array();
  17. if (isset($_SESSION["lightroomFiles"]))
  18. $files = $_SESSION["lightroomFiles"];
  19. $files[] = $file;
  20. $_SESSION["lightroomFiles"] = $files;
  21. exit("success");
  22. } elseif ($action == "remove") {
  23. if (!isset($_POST["file"]))
  24. exit("error: no file specified.");
  25. $file = $_POST["file"];
  26. $files = array();
  27. if (isset($_SESSION["lightroomFiles"]))
  28. $files = $_SESSION["lightroomFiles"];
  29. for($i = 0; $i < count($files); ++$i) {
  30. if ($files[$i] == $file) {
  31. array_splice($files, $i, 1);
  32. break;
  33. }
  34. }
  35. $_SESSION["lightroomFiles"] = $files;
  36. exit("success");
  37. } elseif ($action == "zip") {
  38. $zip = new ZipArchive();
  39. $zipFilename = $zipFolder.session_id().".zip";
  40. if (file_exists($zipFilename))
  41. unlink($zipFilename);
  42. if ($zip->open($zipFilename, ZIPARCHIVE::CREATE) !== TRUE)
  43. exit("error: cannot create zip archive");
  44. $files = array();
  45. if (isset($_SESSION["lightroomFiles"]))
  46. $files = $_SESSION["lightroomFiles"];
  47. for($i = 0; $i < count($files); ++$i)
  48. $zip->addFile($files[$i]);
  49. $zip->close();
  50. exit("success:".$zipFilename);
  51. } elseif ($action == "zipClean") {
  52. // Open a known directory, and proceed to read its contents
  53. if (is_dir($zipFolder)) {
  54. if ($dh = scandir($zipFolder)) {
  55. for ($i = 0; $i < count($dh); ++$i) {
  56. if ($dh[$i] == "." || $dh[$i] == "..")
  57. continue;
  58. $filePath = $zipFolder.$dh[$i];
  59. $stat = stat($filePath);
  60. if (time() - $stat['ctime'] > (30*60))
  61. unlink($filePath);
  62. }
  63. exit("success");
  64. }
  65. }
  66. exit("error: could not open zip folder ".$zipFolder);
  67. } elseif ($action == "sortOut") {
  68. if (!isset($_POST["file"]))
  69. exit("error: no file specified.");
  70. $file = $_POST["file"];
  71. // load blacklist
  72. $blacklistFilename = "blacklist.txt";
  73. $blacklistHandle = fopen($blacklistFilename, "a");
  74. if (!$blacklistHandle)
  75. exit("error: could not open blacklist file.");
  76. if (!fwrite($blacklistHandle, $file."\n"))
  77. exit("error: could not write blacklist file.");
  78. fclose($blacklistHandle);
  79. exit("success");
  80. }
  81. exit("error: unsupported action.");
  82. ?>