| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- session_start();
- header('Content-Type: text/html; charset=utf-8');
- $zipFolder = "zip/";
- $toplevelDir = "pictures/";
- $saveFolder = "pictures_save/";
- if (!isset($_POST["action"]))
- exit("error: no action defined.");
-
- $action = $_POST["action"];
- if ($action == "add") {
- if (!isset($_POST["file"]))
- exit("error: no file specified.");
- $file = $_POST["file"];
-
- if (!file_exists($file))
- exit("error: file does not exist.".$file);
-
- $files = array();
- if (isset($_SESSION["lightroomFiles"]))
- $files = $_SESSION["lightroomFiles"];
-
- $files[] = $file;
-
- $_SESSION["lightroomFiles"] = $files;
-
- exit("success");
- } elseif ($action == "remove") {
- if (!isset($_POST["file"]))
- exit("error: no file specified.");
- $file = $_POST["file"];
-
- $files = array();
- if (isset($_SESSION["lightroomFiles"]))
- $files = $_SESSION["lightroomFiles"];
-
- for($i = 0; $i < count($files); ++$i) {
- if ($files[$i] == $file) {
- array_splice($files, $i, 1);
- break;
- }
- }
-
- $_SESSION["lightroomFiles"] = $files;
-
- exit("success");
- } elseif ($action == "zip") {
- $zip = new ZipArchive();
- $zipFilename = $zipFolder.session_id().".zip";
-
- if (file_exists($zipFilename))
- unlink($zipFilename);
-
- if ($zip->open($zipFilename, ZIPARCHIVE::CREATE) !== TRUE)
- exit("error: cannot create zip archive");
-
- $files = array();
- if (isset($_SESSION["lightroomFiles"]))
- $files = $_SESSION["lightroomFiles"];
- for($i = 0; $i < count($files); ++$i)
- $zip->addFile($files[$i]);
-
- $zip->close();
-
- exit("success:".$zipFilename);
- } elseif ($action == "zipClean") {
- // Open a known directory, and proceed to read its contents
- if (is_dir($zipFolder)) {
- if ($dh = scandir($zipFolder)) {
- for ($i = 0; $i < count($dh); ++$i) {
- if ($dh[$i] == "." || $dh[$i] == "..")
- continue;
-
- $filePath = $zipFolder.$dh[$i];
- $stat = stat($filePath);
- if (time() - $stat['ctime'] > (30*60))
- unlink($filePath);
- }
- exit("success");
- }
- }
- exit("error: could not open zip folder ".$zipFolder);
- } elseif ($action == "sortOut") {
- if (!isset($_POST["file"]))
- exit("error: no file specified.");
- $file = $_POST["file"];
-
- // load blacklist
- $blacklistFilename = "blacklist.txt";
- $blacklistHandle = fopen($blacklistFilename, "a");
- if (!$blacklistHandle)
- exit("error: could not open blacklist file.");
-
- if (!fwrite($blacklistHandle, $file."\n"))
- exit("error: could not write blacklist file.");
-
- fclose($blacklistHandle);
-
- exit("success");
- }
- exit("error: unsupported action.");
- ?>
|