diff --git a/src/_h5ai/php/api.php b/src/_h5ai/php/api.php index 752c3b67..1614abc3 100644 --- a/src/_h5ai/php/api.php +++ b/src/_h5ai/php/api.php @@ -31,6 +31,9 @@ function check_keys($keys) { return $values; } +function delete_tempfile($file) { + @unlink($file); +} list($action) = check_keys(array("action")); @@ -83,15 +86,16 @@ else if ($action === "getarchive") { json_fail(1, "downloads disabled", !$options["download"]["enabled"]); list($id, $as) = check_keys(array("id", "as")); - json_fail(2, "file not found", !preg_match("/^h5ai-selection-/", $id)); + json_fail(2, "file not found", !preg_match("/^package-/", $id)); - $target = H5ai::normalize_path(sys_get_temp_dir(), true) . $id; + $target = $h5ai->getTempAbsPath() . "/" . $id; json_fail(3, "file not found", !file_exists($target)); header("Content-Type: application/octet-stream"); header("Content-Length: " . filesize($target)); header("Content-Disposition: attachment; filename=\"$as\""); header("Connection: close"); + register_shutdown_function("delete_tempfile", $target); readfile($target); } @@ -105,8 +109,8 @@ else if ($action === "getchecks") { $gdinfo = gd_info(); $gd = array_key_exists("JPG Support", $gdinfo) && $gdinfo["JPG Support"] || array_key_exists("JPEG Support", $gdinfo) && $gdinfo["JPEG Support"]; } - $cache = @is_writable($h5ai->getH5aiAbsPath() . "/cache"); - $temp = @is_writable(sys_get_temp_dir()); + $cache = @is_writable($h5ai->getCacheAbsPath()); + $temp = @is_writable($h5ai->getTempAbsPath()); $tar = @preg_match("/tar$/", `which tar`) > 0; $zip = @preg_match("/zip$/", `which zip`) > 0; $convert = @preg_match("/convert$/", `which convert`) > 0; diff --git a/src/_h5ai/php/inc/Archive.php b/src/_h5ai/php/inc/Archive.php index 159e00a4..cc3fa634 100644 --- a/src/_h5ai/php/inc/Archive.php +++ b/src/_h5ai/php/inc/Archive.php @@ -29,7 +29,7 @@ class Archive { return 404; } - $target = H5ai::normalize_path(sys_get_temp_dir(), true) . "h5ai-selection-" . microtime(true) . rand() . "." . $format; + $target = $this->h5ai->getTempAbsPath() . "/package-" . sha1(microtime(true) . rand()) . "." . $format; try { if ($execution === "shell") { diff --git a/src/_h5ai/php/inc/H5ai.php b/src/_h5ai/php/inc/H5ai.php index 64cd827e..4cb2b8c2 100644 --- a/src/_h5ai/php/inc/H5ai.php +++ b/src/_h5ai/php/inc/H5ai.php @@ -86,6 +86,19 @@ class H5ai { } + public function getCacheAbsPath() { + + return $this->h5aiAbsPath . '/cache'; + } + + + public function getTempAbsPath() { + + // return H5ai::normalize_path(sys_get_temp_dir()); + return $this->h5aiAbsPath . '/cache'; + } + + public function getRootAbsHref() { return $this->rootAbsHref; diff --git a/src/_h5ai/php/inc/Thumb.php b/src/_h5ai/php/inc/Thumb.php index 667d206f..173df884 100644 --- a/src/_h5ai/php/inc/Thumb.php +++ b/src/_h5ai/php/inc/Thumb.php @@ -72,7 +72,7 @@ class Thumb { return null; } - $captureAbsPath = $this->h5ai->getH5aiAbsPath() . "/cache/capture-" . sha1($sourceAbsPath) . ".jpg"; + $captureAbsPath = $this->h5ai->getCacheAbsPath() . "/capture-" . sha1($sourceAbsPath) . ".jpg"; if (!file_exists($captureAbsPath) || filemtime($sourceAbsPath) >= filemtime($captureAbsPath)) { $cmd = str_replace("[SOURCE]", $sourceAbsPath, $cmd);