Skip to content

Commit

Permalink
Merge #531 from branch 'lobid-gnd-408-urlencodingImagesproxy' of gith…
Browse files Browse the repository at this point in the history
…ub.com:hbz/lobid
  • Loading branch information
dr0i committed Oct 15, 2024
2 parents e1083c9 + 6f891a3 commit c3d7e95
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions gatsby/lobid/static/imagesproxy.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
<?php

$url = $_GET['url'];
$url=str_replace(" ", "%20", $url);
// encode the URL
$url = implode("/", array_map("rawurlencode", explode("/", $url)));
// restore the colon of the protocol
$positionOfColon = strpos($url,"%");
$url= substr_replace($url,":",$positionOfColon,3);
// restore the query Parameter
$positionOfQueryParameter = strrpos($url,"%3F");
$url= substr_replace($url,"?",$positionOfQueryParameter,3);
// restore the
$positionOfEqual = strrpos($url,"%3D", $positionOfQueryParameter);
$url= substr_replace($url,"=",$positionOfEqual,3);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","User-Agent: imagesproxy/0.2 (https://lobid.org/)"));

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$filename = basename($url);

Expand All @@ -26,7 +39,7 @@
}

header('Content-type: ' . $ctype);
echo $output = curl_exec($ch);
curl_close($ch);
echo curl_exec($ch);
curl_close($ch);
?>

0 comments on commit c3d7e95

Please sign in to comment.