From 00e07490847f46823e05edfb9e957e1b99487c50 Mon Sep 17 00:00:00 2001 From: paulr Date: Mon, 1 Aug 2011 03:49:27 +1000 Subject: [PATCH] modified the way the directory detection works... its not foolproof, and not standard in anyway. --- bin/downloadfile.php | 22 +++++++++++++++------- 1 files changed, 15 insertions(+), 7 deletions(-) diff --git a/bin/downloadfile.php b/bin/downloadfile.php index c0cbec8..818dead 100644 --- a/bin/downloadfile.php +++ b/bin/downloadfile.php @@ -18,7 +18,7 @@ if($url == "" || $file == "") { // first check any directories in $file are in existence $splfile = explode("/", $file); if(count($splfile) > 1) { - $tomake = "$repostore/$matched/"; + $tomake = ""; for($i = 0; $i < count($splfile)-1; $i++) { $tomake .= "/".$splfile[$i]; echo("making directory $tomake"); @@ -39,7 +39,7 @@ if(file_exists("$file")) { } else { error_log("lock succeeded, dieing in the arse"); unlink("$file"); - unlink("$file.size"); + if(file_exists("$file.size")) unlink("$file.size"); } } @@ -71,12 +71,20 @@ if(!$localfile) { // get the headers from the remote request and use them to hurt people $contentlen = 0; $contenttype = ""; + +// detecting a remote directory on a web session is near impossible, this is the best i can come up with +// - check for a redirection header, then look for a trailing / on the url... best of luck to me foreach($http_response_header as $key => $val) { - if(preg_match("/HTTP.*30[1-9].*/", $val)) { - fclose($localfile); - unlink($file); - mkdir($file); - exit(0); + if(preg_match("/.*Location:.*/", $val)) { + echo "got location as $val\n"; + $realloc = preg_replace("/.*[: ]/", "", $val); + if(preg_match("/.*\/$/", $realloc)) { + echo "matched\n"; + fclose($localfile); + unlink($file); + mkdir($file); + exit(0); + } } // get content length form upstream and print if(preg_match("/^Content-Length:.*/", $val)) { -- 1.7.0.4