diff options
author | steckbrief <steckbrief@chefmail.de> | 2016-12-12 12:58:12 +0100 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2016-12-12 12:58:12 +0100 |
commit | 0549800afeb7b8db389d79a9fd48feecf875ab23 (patch) | |
tree | da1dfcd654cdc312a88cda2fc2e2da54edbe3b98 /src/loadArtifact.php | |
parent | 13dd3487d7c68c7067b4dcef920aa7afe6c740e2 (diff) |
Error handling improved, logging included
Diffstat (limited to '')
-rw-r--r-- | src/loadArtifact.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/loadArtifact.php b/src/loadArtifact.php new file mode 100644 index 0000000..6205164 --- /dev/null +++ b/src/loadArtifact.php @@ -0,0 +1,34 @@ +<?php +$mvnBaseUrl = 'http://repo1.maven.org/maven2'; + +$requestedArtifact = $_SERVER["REQUEST_URI"]; +$requestedArtifact = str_replace('/mvn', '', $requestedArtifact); +$baseLocalFolder = __DIR__; +$localFolder = $baseLocalFolder.substr($requestedArtifact, 0, strripos($requestedArtifact, '/')); +//echo $localFolder."<br>"; +if (!is_dir($localFolder)) { + mkdir($localFolder, 0770, true); +} + +$srcUrl = $mvnBaseUrl.$requestedArtifact; +//echo $srcUrl."<br>"; +$src = fopen($srcUrl, 'r'); + +$dstPath = $baseLocalFolder.$requestedArtifact; +//echo $dstPath; +$dst = fopen($dstPath, 'w'); + +$filesize = stream_copy_to_stream($src, $dst); + +if (0 == $filesize) { + unlink($dstPath); + unlink($localFolder); +} + +if (is_file($dstPath)) { + chmod($dstPath, 0660); + header('Location: http://'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]); +} else { + header('HTTP/1.0 404 Not Found'); +} +?> |