<?php
// spec_img.php
// RJM Programming
// October, 2016
// Look for an image spec in the hosting domain and glob it

 if (isset($_POST['documentroot'])) {
  $changeto=$_POST['documentroot'];
 } else if (isset($_GET['documentroot'])) {
  $changeto=$_GET['documentroot'];
 } else {
  $changeto=$_SERVER['DOCUMENT_ROOT'];
 }
 if (strpos($changeto, "/") === false && strpos($changeto, "\\") === false && strpos($changeto, ":") === false) {
  $changeto=urldecode($changeto);
 }
 if (strpos($changeto, "/") !== false) $changeto = str_replace("//","/",($changeto . "/"));
 if (strpos($changeto, "\\") !== false) $changeto = str_replace("\\\\","\\",($changeto . "\\"));
 $htmlis="<!doctype html><html><body></body></html>";
 $imgurls="";
 if (isset($_POST['imgurls'])) {
   if (strpos($_POST['imgurls'], "//") !== false) {
    $imgurls=$_POST['imgurls'];
   } else {
    $imgurls=urldecode($_POST['imgurls']);
   }
 } else if (isset($_GET['imgurls'])) {
   if (strpos($_GET['imgurls'], "//") !== false) {
    $imgurls=$_GET['imgurls'];
   } else {
    $imgurls=urldecode($_GET['imgurls']);
   }
 }
 if ($imgurls != "") {
   $protistwo=explode("//", $imgurls);
   if (isset($_POST['documentrooturl'])) {
    $urldomain=$_POST['documentrooturl'];
   } else if (isset($_GET['documentrooturl'])) {
    $urldomain=$_GET['documentrooturl'];
   } else {
    $urldomain=$protistwo[0] . "//" . $_SERVER['SERVER_NAME'] . "/";
   }
   if (strpos($urldomain, "/") === false && strpos($urldomain, "\\") === false && strpos($urldomain, ":") === false) {
    $urldomain=urldecode($urldomain);
   }
   $csvs = explode(",", $imgurls);
   for ($i=0; $i<sizeof($csvs); $i++) {
    if (strpos($csvs[$i], $urldomain) !== false) {
     foreach (glob(str_replace($urldomain, $changeto ,$csvs[$i])) as $filename) {
       $htmlis=str_replace("</body>", "<img style='width:100%;' title='image from " . $urldomain . "' src='" . str_replace($changeto, $urldomain, $filename) . "'></img><br></body>", $htmlis);       
     }
    }
   }
 }
 echo $htmlis;
?>


