X-Git-Url: http://git.pjr.cc/?p=glcas.git;a=blobdiff_plain;f=bin%2Fdownloadfile.php;h=c0cbec8ccee407c4656ed056b9778d4f947f2f13;hp=47606270e2a4a0328915c0a2fd5c985b731d54bb;hb=fc40a152c4238a9208086bb1203add8322861675;hpb=136e5dafcbb81dc6e347a6936e715d8ac134c5a7 diff --git a/bin/downloadfile.php b/bin/downloadfile.php index 4760627..c0cbec8 100644 --- a/bin/downloadfile.php +++ b/bin/downloadfile.php @@ -15,6 +15,17 @@ if($url == "" || $file == "") { exit(0); } +// first check any directories in $file are in existence +$splfile = explode("/", $file); +if(count($splfile) > 1) { + $tomake = "$repostore/$matched/"; + for($i = 0; $i < count($splfile)-1; $i++) { + $tomake .= "/".$splfile[$i]; + echo("making directory $tomake"); + if(!is_dir($tomake)) mkdir($tomake); + } +} + // ok, we kick off a download if(file_exists("$file")) { @@ -33,17 +44,37 @@ if(file_exists("$file")) { } $remotefile = fopen($url, "r"); + +// check if ther mote file started +if(!$remotefile) { + foreach($http_response_header as $key => $val) { + if(preg_match("/HTTP.*404.*/", $val)) { + echo "got a 404 touching 404 file\n"; + touch("$file.404"); + exit(0); + } + } +} else { + if(file_exists("$file.404")) { + unlink("$file.404"); + } +} + $localfile = fopen($file, "w"); $lockres = flock($localfile, LOCK_EX); if(!$localfile) { - erorr_log("something went plop"); + echo "something went plop\n"; return; } + + // get the headers from the remote request and use them to hurt people $contentlen = 0; $contenttype = ""; foreach($http_response_header as $key => $val) { if(preg_match("/HTTP.*30[1-9].*/", $val)) { + fclose($localfile); + unlink($file); mkdir($file); exit(0); }