apache-img.php

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
body { 
  margin: 0;
  padding: 0;
  font-size: 0;
  background: #444
}
hr {
  margin: 1rem 0;
}
img {
  min-width: 50px;
  max-width: 33%;
  max-height: 250px;
  background: white;
  margin: 5px;
  border: 1px solid #aaa;
  image-rendering: pixelated;
}
a { 
  color: white;
  display: inline-block;
  font-size: 16px;
  margin: 0.25rem 1rem;
}
a:visited {
  color: pink;
}
input {
  margin: 10px 15px;
  color: white;
  padding: 4px;
  font-weight: bold;
  font-size: 14px;
  background: #888;
}
b { 
  font-size: 14px; 
  color: yellow; 
}
::placeholder {
  color: #bbb;
  font-style: italic;
}
</style>
</head>
<body>
<form>
<input name=u placeholder="new url">
</form>
<?php
$parts = explode('?', $_GET['u']);
$URL = $parts[0];
$data = file_get_contents($URL);
preg_match_all('/((?<=href=")[^"]*)/i', $data, $matches);

$parsed = parse_url($URL);
$baseurl = $parsed["scheme"] . "://" . $parsed["host"];
$matches = $matches[0];
$base = trim($URL, '/');

$images = [];
$links = [];
$other = [];

foreach($matches as $img) {
  $parts = explode('.', strtolower($img));
  $ext = array_pop($parts);

  if ($img[0] == '/') {
    $use = $baseurl;
  } else {
    $use = "${base}/";
  }
  if(in_array($ext, ['png','gif','svg','jpeg','jpg','bmp'])) {
    $images[] =  "<img title='$img' data-src=$use$img>";
  } else if ($img[0] != '?') {
    if ($img[-1] == '/') {
      $link = "$use/$img";
      $links[] = "<a href=?u=$link>$img</a>";
    } else {
      $other[] = "<a href=$use$img>$img</a>";
    }
  }
}

foreach([$links, $images, $other] as $w) {
  echo implode("\n", $w) . "<hr>";
}
echo "<b>${_GET['u']}</b><br/>" . implode("\n", $links) . "<hr>";
  ?>
<script>
var ix = -1;
function fn() {
  ix++;
  if(!document.images[ix]) return;
  document.images[ix].onload = document.images[ix].onerror = fn;
  document.images[ix].src = document.images[ix].dataset.src;
}
fn();
</script>