<?php
// fileinfotable.php 
// Create table of information about filespec or report about dead links
// RJM Programming
// October, 2014

$fsev = '  document.getElementById("files").addEventListener("change", handleFileSelect, false); ';
$iscalled = "";
$mode = "Read bytes";
$title = "File Information Table";
$deadlinks = "";
$snapshot = "";
$myfe = "myf=";
$flh = "";
$omyh1stuff = "";
$fnameis = "";
$lnameis = "";
$pnameis = "";
$undefined = " ";
$urlsuffix = "";
$urllist = "";
$statuslist = "";
$linelist = "";
$collist = "";


if (isset($_GET['myf'])) {
  $huhis = explode("strong>", $_GET['myf']);
  if (sizeof($huhis) >= 3) $undefined = str_replace("</", " ", " " . $huhis[1]);
} else if (isset($_POST['myf'])) {
  if ($_POST['myf'] != "") $undefined = " " . $_POST['myf'] . " ";
}

if (isset($_GET['deadlinks'])) {
     $urlsuffix = "?deadlinks=" . urlencode(urldecode($_GET['deadlinks']));
     $omyh1stuff = " mh(); "; //" omyh1=document.getElementById('myh1'); if (omyh1.innerHTML.indexOf(' Please wait ') == -1) { omyh1.innerHTML = omyh1.innerHTML + ' ... Please wait while we analyze your URLs ... ';  } ";
     $title = "Dead Links via File of Absolute URLs Report";
     $deadlinks = "y";
     $myfe = "deadlinks=Report%20list%20of%20dead%20links%20of%20file%20of%20URLs&myf=";
     if ($_GET['deadlinks'] == "") {
       $mode = "Report list of dead links of file of Absolute URLs";
     } else {
       $mode = urldecode($_GET['deadlinks']);
     }
} else if (isset($_POST['deadlinks'])) {
     $urlsuffix = "?deadlinks=" . urlencode(urldecode($_POST['deadlinks']));
     $omyh1stuff = " mh(); "; //" omyh1=document.getElementById('myh1');  if (omyh1.innerHTML.indexOf(' Please wait ') == -1) { omyh1.innerHTML = omyh1.innerHTML + ' ... Please wait while we analyze your URLs ... ';  } ";
     $title = "Dead Links via File of Absolute URLs Report";
     $deadlinks = "y";
     $myfe = "deadlinks=Report%20list%20of%20dead%20links%20of%20file%20of%20URLs&myf=";
     if ($_POST['deadlinks'] == "") {
       $mode = "Report list of dead links of file of Absolute URLs";
     } else {
       $mode = urldecode($_POST['deadlinks']);
     }
}


function url_exists($url) {  // Thanks to http://stackoverflow.com/questions/2280394/how-can-i-check-if-a-url-exists-via-php
global $fnameis;
global $lnameis;
global $pnameis;
    global $flh;
    $exists = false;
    $url = urldecode($url);
    if (strpos($url, "https:") !== false || strpos($url, "HTTPS:") !== false || strpos($url, "http:") !== false || strpos($url, "HTTP:") !== false) {
     if (strpos(substr(trim($url), 8), "/") === false) $url = trim($url) . "/";
     $wordsare = explode("/", $url);
     if ($wordsare[sizeof($wordsare) - 1] != "") {
        if (strpos($wordsare[sizeof($wordsare) - 1], ".") === false && strpos($wordsare[sizeof($wordsare) - 1], "?") === false && strpos($wordsare[sizeof($wordsare) - 1], "&") === false) {
           $url = trim($url) . "/";
        }
     }
     //if (!$fp = curl_init($url)) return false;
     //curl_close($fp);
     //return true;
$curl = curl_init();  // thanks to http://stackoverflow.com/questions/7852005/how-to-check-if-a-url-exists-with-php-and-make-it-time-out-after-a-number-of-sec
curl_setopt($curl, CURLOPT_URL, trim($url));
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($curl);
curl_close($curl);
preg_match("/HTTP\/1\.[1|0]\s(\d{3})/",$data,$matches);
return ($matches[1] == 200);
    } else if (strpos($url, "http:") !== false || strpos($url, "HTTP:") !== false) {
     $file = $url;
     $file_headers = @get_headers($file);
     $flh = $file_headers[0];
     if (strpos($file_headers[0], " 404 ") !== false) { // == 'HTTP/1.1 404 Not Found') {
      $exists = false;
     } else {
      $exists = true;
     }
   } else {
     $exists = file_exists($url);
   }
   return $exists;
}

function echop($ine) {
global $fnameis;
global $lnameis;
global $pnameis;
  echo "<html><body><script type='text/javascript'> top.document.title='" . $ine . "';  top.document.body.innerHTML = top.document.body.innerHTML + '<p>" . str_replace("\n", "", $ine) . "</p><br>'; </script><p>" . $ine . "</p></body></html>";
}

function prelook($xinfl) {
global $fnameis;
global $lnameis;
global $pnameis;
global $undefined;
  $outinfl = $xinfl;
  $fnameis = "";
  if (strpos($xinfl, "http(") !== false || strpos($xinfl, "HTTP(") !== false) {
    $zxinfl = explode(")", substr($xinfl, 5));
    $hbit = "(" . $zxinfl[0] . ")";
    $outinfl = str_replace($hbit, "", $outinfl);
    $fnameis = str_replace(" undefined ", $undefined, str_replace("(", " in ", str_replace(")", "", str_replace("|", " on line ", str_replace("@", " at column ", $hbit)))));
  }
  return $outinfl;
}


function pluck($sdelim, $pstr, $bstr, $edelim, $ourln, $ourcp) {
global $urllist, $statuslist, $linelist, $collist, $fnameis;

  if ($sdelim == "") {
    $preturl = explode($edelim, $bstr);
    $pturl = explode("<", $preturl[0]);
    $turl = explode(chr(92), $pturl[0]);
  } else {
    $preturl = explode($sdelim, $bstr);
    $pturl = explode("<", $preturl[0]);
    $turl = explode(chr(92), $pturl[0]);
  }
  $endl = "";
  if (strpos(substr(trim($pstr . $turl[0]), 8), "/") === false) $turl[0] = trim($turl[0]) . "/";
  $urllist .= $pstr . $turl[0] . "<br>";
  if (url_exists($pstr . $turl[0])) {
    $statuslist .= "exists<br>";
  } else {
    $statuslist .= "<font color=red>does not</font> exist<br>";
  }
  $linelist .= $ourln . "<br>";
  $collist .= $ourcp . "<br>";
  return $pstr . "(" . $fnameis . "|" . $ourln . "@" . $ourcp . ")" . $turl[0] . $edelim;
}

function makeintolist($inst) {    // via web server filelist via glob
global $urllist, $statuslist, $linelist, $collist, $fnameis, $urlsuffix;

  $urlbit = "";
  $outst = $inst;
  $interimst = $inst;
  $interimst = explode("\n", $inst);
  
  if (sizeof($interimst) > 0) $outst = "";

  for ($ik=0; $ik<sizeof($interimst); $ik++) {
  $xinst = $interimst[$ik];
  $iposis = strpos($interimst[$ik], "http");
  while ($iposis !== false) {
    if ($iposis == 0) {
      $interimst[$ik] = "xxxx" . substr($xinst, ($iposis + 4));
      if (substr($xinst, ($iposis + 4), 1) != "_") $urlbit = pluck("", "http", substr($xinst, ($iposis + 4)), "\n", ($ik + 1), ($iposis + 1));
      $outst .= $urlbit;
      $xinst = $interimst[$ik];
      $urlbit = "";
    } else {
      $interimst[$ik] = substr($xinst, 0, $iposis) . "xxxx" . substr($xinst, ($iposis + 4));
      if (substr($xinst, ($iposis + 4), 1) != "_") $urlbit = pluck(substr($xinst, ($iposis - 1), 1), "http", substr($xinst, ($iposis + 4)), "\n", ($ik + 1), ($iposis + 1));
      $xinst = $interimst[$ik];
      $outst .= $urlbit;
      $urlbit = "";
      
    }
    $iposis = strpos($interimst[$ik], "http");
  }
  
  $iposis = strpos($interimst[$ik], "HTTP");
  while ($iposis !== false) {
    if ($iposis == 0) {
      $interimst[$ik] = "xxxx" . substr($xinst, ($iposis + 4));
      if (substr($xinst, ($iposis + 4), 1) != "_") $urlbit = pluck("", "HTTP", substr($xinst, ($iposis + 4)), "\n", ($ik + 1), ($iposis + 1));
      $xinst = $interimst[$ik];
      $outst .= $urlbit;
      $urlbit = "";
    } else {
      $interimst[$ik] = substr($xinst, 0, $iposis) . "xxxx" . substr($xinst, ($iposis + 4));
      if (substr($xinst, ($iposis + 4), 1) != "_") $urlbit = pluck(substr($xinst, ($iposis - 1), 1), "HTTP", substr($xinst, ($iposis + 4)), "\n", ($ik + 1), ($iposis + 1));
      $xinst = $interimst[$ik];
      $outst .= $urlbit;
      $urlbit = "";
    }
    $iposis = strpos($interimst[$ik], "HTTP");
  }
  }
  
  return $outst;
}

function readandprocess($infl) {
global $fnameis;
global $lnameis;
global $pnameis;
  global $flh, $urlsuffix;
  $fnameis = "";
  $endl = "";
  $outfl = "<table>";
  if (strpos($infl, "@!~*^@") !== false) {
     if (strpos($infl, "@!~*^@") < 80) {
       $spl = explode("@!~*^@", $infl);
       $infl = $spl[1];
       $fnameis = $spl[0];
     }
  }
  if ($fnameis != "" || (strpos(("*" . $infl), "*http") === false && strpos(("*" . $infl), "*HTTP") === false)) {
    $urls = explode("\n", makeintolist($infl));
    $fnameis = "";
    if ($urlsuffix != "") $outfl = "";
  } else {
    $urls = explode("\n", $infl);
  }
  if ($outfl != "") {
  for ($ij=0; $ij<sizeof($urls); $ij++) {
   $urls[$ij] = prelook($urls[$ij]);
   if ($urls[$ij] != "") {
     $endl = "";
     if (strpos(substr(trim($urls[$ij]), 8), "/") === false) $urls[$ij] = trim($urls[$ij]) . "/";
     if (url_exists($urls[$ij] . $endl)) {
      $outfl .= "<tr><td><b>" . $urls[$ij] . $endl . "</b> exists" . $fnameis . $lnameis . $pnameis . ".</td></tr>";
     } else {
      $outfl .= "<tr><td><b>" . $urls[$ij] . $endl . "</b> <font color=red>does not</font> exist" . $fnameis . $lnameis . $pnameis . ".</td></tr>";
     }
     $flh = "";
   }
  }
  $outfl .= "</table>";
  }
  return $outfl;
}

function on_to($on, $to) {
global $fnameis;
global $lnameis;
global $pnameis;
     if (url_exists(urldecode($on))) {
       if ($to == "") {
         echop(urldecode($on) . " exists" . $fnameis . $lnameis . $pnameis . ".\n");
       } else {
         file_put_contents($to, file_get_contents($to) . urldecode($on) . " exists" . $fnameis . $lnameis . $pnameis . ".\n");
       }
       exit;
     } else {
       if ($to == "") {
         echop(urldecode($on) . " <font color=red>does not</font> exist" . $fnameis . $lnameis . $pnameis . ".\n");
       } else {
         file_put_contents($to, file_get_contents($to) . urldecode($on) . " <font color=red>does not</font> exist" . $fnameis . $lnameis . $pnameis . ".\n");
       }
       exit;
     }
}

   $outrep = "";
   if (isset($_GET['justreportto'])) {
     $outrep = urldecode($_GET['justreportto']);
     if (strpos($outrep, "/") === false && strpos($outrep, "\\") === false) {
       $outrep = dirname(__FILE__) . "/" . $outrep;
     }
   } else if (isset($_POST['justreportto'])) {
     $outrep = urldecode($_POST['justreportto']);
     if (strpos($outrep, "/") === false && strpos($outrep, "\\") === false) {
       $outrep = dirname(__FILE__) . "/" . $outrep;
     }
   }

   if (isset($_GET['justreporton'])) {
     on_to(urldecode($_GET['justreporton']), $outrep);
     exit;
   } else if (isset($_POST['justreporton'])) {
     on_to(urldecode($_POST['justreporton']), $outrep);
     exit;
   } else {

   if (isset($_GET['fsp'])) {
     $iscalled = "y";
     $fsp = $_GET['fsp'];
   } else if (isset($_POST['fsp'])) {
     $iscalled = "y";
     $fsp = $_POST['fsp'];
   } else if ($deadlinks == "") {
     $fsp = "*";
     $ext = ".xml";
   } else {
     $fsp = "index";
     $ext = ".html";
   }
   
   if (isset($_GET['ext'])) {
     if ($iscalled == "") $fsp = "";
     $iscalled = "y";
     $ext = $_GET['ext'];
   } else if (isset($_POST['ext'])) {
     if ($iscalled == "") $fsp = "";
     $iscalled = "y";
     $ext = $_POST['ext'];
   } else if ($iscalled != "") {
     $ext = "";
   } 
         
   if (isset($_GET['dir'])) {
     $iscalled = "y";
     $dir = $_GET['dir'];
   } else if (isset($_POST['dir'])) {
     $iscalled = "y";
     $dir = $_POST['dir'];
   } else if ($deadlinks == "") {
     $dir = '/'; // '/Library/pgAgent/Downloads/CRL/';
   } else {
     $dir = 'http://'; 
   }
   
   if ($iscalled == "") {
    $outhtml = "<!DOCTYPE html>\n<html><head><title>" . $title . "</title>\n";
    
    $outhtml .= '
<script type="text/javascript">
  var imgmode=" ";
  var omyh1;
  var fcont="";
  var bigi=0;
  var bigj=0;
  var wl="";
  var doneonce="";
  var presm="sm";
  var bigbuffer="";
  var prevmy_res="";
  var bigf=new Array();
  var urlsuf="' . $urlsuffix . '";
  
  function mh() { omyh1=document.getElementById("myh1");   if (urlsuf != "" && omyh1.innerHTML.indexOf(" Please wait ") == -1) { omyh1.innerHTML = omyh1.innerHTML + " ... Please wait while we analyze your URLs ... ";  } }    
  
  function dlbclick() {
     //alert(document.getElementById("flist").value);
            document.getElementById("dlb").click();
  }
  
  function check(thisfordelim) {
    var outval = thisfordelim.value;
    if (outval.length > 0) {
      if ((outval + "@!@").indexOf(String.fromCharCode(47) + "@!@") == -1 && (outval + "@!@").indexOf(String.fromCharCode(92) + "@!@") == -1) {
        if (outval.indexOf(String.fromCharCode(92)) != -1) {
          outval = outval + String.fromCharCode(92);
          thisfordelim.value = outval;
        } else if (outval.indexOf(String.fromCharCode(47)) != -1) {
          outval = outval + String.fromCharCode(47);
          thisfordelim.value = outval;
        } else {
          outval = outval + String.fromCharCode(47);
          thisfordelim.value = outval;
        }
      }
    }
    return outval;
  }

  function readBlob(opt_startByte, opt_stopByte) {

    omyh1 = document.getElementById("myh1");
    
' . $omyh1stuff . '
    
    var files = document.getElementById("file").files;
    if (!files.length) {
      alert("Please select a file!");
      return;
    }

    var file = files[0];
    var start = parseInt(opt_startByte) || 0;
    var stop = parseInt(opt_stopByte) || file.size - 1;

    var reader = new FileReader();

     if (imgmode == " " && file.type.match(' . "'" . 'image.*' . "'" . ')) {
       imgmode = "y";
     } else if (imgmode == " ") {
       imgmode = "";
     }


      // Only process image files.
     if (imgmode == "y" || file.type.match(' . "'" . 'image.*' . "'" . ') || file.type.indexOf(' . "'" . '/pdf' . "'" . ') != -1 || file.type.indexOf(' . "'" . 'audio/' . "'" . ') != -1 || file.type.indexOf(' . "'" . 'video/' . "'" . ') != -1 || file.type.indexOf(' . "'" . 'application/' . "'" . ') != -1) {
      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          // Render thumbnail.
          if (document.body.innerHTML.indexOf(' . "'" . '" title="' . "'" . ' + escape(theFile.name) + ' . "'" . "'" . ' ) == -1) {
          var vid = theFile.name.replace(".","");
          var mvid = theFile.name.replace(".","m");
          if (theFile.type.indexOf("image/") != -1 || theFile.type.indexOf("/pdf") != -1 || theFile.type.indexOf("audio/") != -1 || theFile.type.indexOf("video/") != -1 || theFile.type.indexOf("application/") != -1) {
          var span = document.createElement("span");
          var elt = "img";
          if (theFile.type.indexOf("image/") == -1) elt = "iframe";
          if (theFile.type.indexOf("/pdf") != -1) {
            span.innerHTML = [' . "'" . '<a class=pdfa href=#' . "'" . ' + vid + ' . "'" . ' onclick=document.getElementById("' . "'" . ' + vid + ' . "'" . '").style.display="block"; class="thumb" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"><img src=icon_pdf.gif title=Pdf />' . "'" . ' + escape(theFile.name) + ' . "'" . '</a>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("audio/") != -1) {
            span.innerHTML = [' . "'" . '<a class=pdfa href=#' . "'" . ' + vid + ' . "'" . ' onclick=document.getElementById("' . "'" . ' + vid + ' . "'" . '").style.display="block"; class="thumb" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"><img src=icon_external.gif title=Pdf />' . "'" . ' + escape(theFile.name) + ' . "'" . '</a>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("video/") != -1) {
            span.innerHTML = [' . "'" . '<a class=pdfa href=#' . "'" . ' + vid + ' . "'" . ' onclick=document.getElementById("' . "'" . ' + vid + ' . "'" . '").style.display="block"; class="thumb" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"><img src=icon_external.gif title=Pdf />' . "'" . ' + escape(theFile.name) + ' . "'" . '</a>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("application/") != -1 && theFile.type.indexOf("spreadsheet") != -1) {
            span.innerHTML = [' . "'" . '<a class=pdfa href=#' . "'" . ' + vid + ' . "'" . ' onclick=document.getElementById("' . "'" . ' + vid + ' . "'" . '").style.display="block"; class="thumb" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"><img src=icon_xls.gif title=Pdf />' . "'" . ' + escape(theFile.name) + ' . "'" . '</a>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("application/") != -1 && (theFile.type.indexOf("document") != -1 || theFile.type.indexOf("msword") != -1)) {
            span.innerHTML = [' . "'" . '<a class=pdfa href=#' . "'" . ' + vid + ' . "'" . ' onclick=document.getElementById("' . "'" . ' + vid + ' . "'" . '").style.display="block"; class="thumb" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"><img src=icon_doc.gif title=Pdf />' . "'" . ' + escape(theFile.name) + ' . "'" . '</a>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("application/") != -1) {
            span.innerHTML = [' . "'" . '<a class=pdfa href=#' . "'" . ' + vid + ' . "'" . ' onclick=document.getElementById("' . "'" . ' + vid + ' . "'" . '").style.display="block"; class="thumb" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"><img src=icon_popup.gif title=Pdf />' . "'" . ' + escape(theFile.name) + ' . "'" . '</a>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else {
            span.innerHTML = [' . "'" . '<img onclick=document.getElementById("' . "'" . ' + vid + ' . "'" . '").style.display="block"; class="thumb" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"/>' . "'" . '].join(' . "'" . '' . "'" . ');
		  }
          document.getElementById(' . "'" . 'imglist' . "'" . ').insertBefore(span, null);
          }
          var xxxx="<p id="' . "" . ' + mvid + ' . "" . '"  align=center>Filename is <strong>" + maybemedia(escape(theFile.name) + "</strong> ... Type is (" + (theFile.type || "n/a") + ") ... Date is ") + (theFile.lastModifiedDate ? theFile.lastModifiedDate.toLocaleDateString() : "n/a") + " ... Size is " + theFile.size + " bytes </p>";
          var span1 = document.createElement("span");
          span1.innerHTML = xxxx;
          document.getElementById(' . "'" . 'imglist' . "'" . ').insertBefore(span1, null);
          if (theFile.type.indexOf("image/") != -1 || theFile.type.indexOf("/pdf") != -1 || theFile.type.indexOf("audio/") != -1 || theFile.type.indexOf("video/") != -1 || theFile.type.indexOf("application/") != -1) {
          var span2 = document.createElement("span");
          if (theFile.type.indexOf("/pdf") != -1) {
            span2.innerHTML = [' . "'" . '<iframe class=big id="' . "'" . ' + vid + ' . "'" . '" style="display:none;" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"/>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("audio/") != -1) {
            span2.innerHTML = [' . "'" . '<audio controls=controls autoplay=autoplay class=big id="' . "'" . ' + vid + ' . "'" . '" style="display:none;" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"/>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("video/") != -1) {
            span2.innerHTML = [' . "'" . '<video controls=controls autoplay=autoplay class=big id="' . "'" . ' + vid + ' . "'" . '" style="display:none;" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"/>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("application/") != -1) {
            span2.innerHTML = [' . "'" . '<iframe class=big id="' . "'" . ' + vid + ' . "'" . '" style="display:none;" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"/>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else {
            span2.innerHTML = [' . "'" . '<img class=big id="' . "'" . ' + vid + ' . "'" . '" style="display:none;" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"/>' . "'" . '].join(' . "'" . '' . "'" . ');
          }
          document.getElementById(' . "'" . 'imglist' . "'" . ').insertBefore(span2, null);
          }
          }
        };
      })(file);

           reader.readAsDataURL(file);
           
      } else if (imgmode == "y") {
      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          var vid = theFile.name.replace(".","");
          var mvid = theFile.name.replace(".","m");
          var xxxx="<p id="' . "" . ' + mvid + ' . "" . '"   align=center>Filename is <strong>" + maybemedia(escape(theFile.name) + "</strong> ... Type is (" + (theFile.type || "n/a") + ") ... Date is ") + (theFile.lastModifiedDate ? theFile.lastModifiedDate.toLocaleDateString() : "n/a") + " ... Size is " + theFile.size + " bytes </p>";
          var span1 = document.createElement("span");
          span1.innerHTML = xxxx;
          document.getElementById(' . "'" . 'imglist' . "'" . ').insertBefore(span1, null);
        };
      })(file);

           reader.readAsDataURL(file);

      } else {
      


    // If we use onloadend, we need to check the readyState.
   
    reader.onloadend = function(evt) {
      if (evt.target.readyState == FileReader.DONE) { // DONE == 2
        document.getElementById("byte_content").textContent = evt.target.result;
        document.getElementById("byte_range").textContent = 
            ["Read bytes: ", start + 1, " - ", stop + 1,
             " of ", file.size, " byte file"].join("");
        process(evt.target.result);
      }
    };
			var blob = file.slice(start, stop + 1);
    		reader.readAsBinaryString(blob);
    }
    

  }
  
  function doonload() {
    omyh1 = document.getElementById("myh1");

if (window.File && window.FileReader && window.FileList && window.Blob) {
  var iii=0;
} else {
  document.getElementById("files").style.display = "none";
  document.getElementById("file").style.display = "none";
  if (1 == 2) { alert("The File APIs are not fully supported in this browser."); }
}
  var ourf=location.search.split("myf=")[1] ? location.search.split("myf=")[1].split("&")[0] : ""; 
  document.body.innerHTML = document.body.innerHTML + decodeURIComponent(ourf);

  document.querySelector(' . "'.readBytesButtons'" . ').addEventListener(' . "'click'" . ', function(evt) {
    if (evt.target.tagName.toLowerCase() == "button") {
      var startByte = evt.target.getAttribute("data-startbyte");
      var endByte = evt.target.getAttribute("data-endbyte");
      readBlob(startByte, endByte);
    }
  }, false);
  
' . $fsev . '  
  
  }
  
    
 function maybemedia(inidea) {
   var outidea = inidea;
   var parts = inidea.split("<");
   var pdfi = "icon_pdf.gif";
   var doci = "icon_doc.gif";
   var xlsi = "icon_xls.gif";
   var appi = "icon_popup.gif";
   var audioi = "icon_external.gif";
   var dparts = String.fromCharCode(34) + parts[0] + String.fromCharCode(34);
   var videoi = "icon_external.gif";
   if (inidea.indexOf("/pdf") != -1) {
     outidea = inidea.replace(" Type is ", "<img onclick=window.open(' . "'" . '" + parts[0] + "' . "'" . ',' . "'" . '_blank' . "'" . '); width=45 height=45 src=' . "'" . '" + pdfi + "' . "'" . ' title=' . "'" . '" + parts[0] + "' . "'" . ' /> Type is ");
   } else if (inidea.indexOf("audio/") != -1) {
     outidea = inidea.replace(" Type is ", "<img onclick=window.open(' . "'" . '" + parts[0] + "' . "'" . ',' . "'" . '_blank' . "'" . '); width=45 height=45 src=' . "'" . '" + audioi + "' . "'" . ' title=' . "'" . '" + parts[0] + "' . "'" . ' /> Type is ");
   } else if (inidea.indexOf("video/") != -1) {
     outidea = inidea.replace(" Type is ", "<img onclick=window.open(' . "'" . '" + parts[0] + "' . "'" . ',' . "'" . '_blank' . "'" . '); width=45 height=45 src=' . "'" . '" + videoi + "' . "'" . ' title=' . "'" . '" + parts[0] + "' . "'" . ' /> Type is ");
   } else if (inidea.indexOf("application/") != -1 && inidea.indexOf("spreadsheet") != -1) {
     outidea = inidea.replace(" Type is ", "<img onclick=window.open(' . "'" . '" + parts[0] + "' . "'" . ',' . "'" . '_blank' . "'" . '); width=45 height=45 src=' . "'" . '" + xlsi + "' . "'" . ' title=' . "'" . '" + parts[0] + "' . "'" . ' /> Type is ");
   } else if (inidea.indexOf("application/") != -1 && (inidea.indexOf("document") != -1 || inidea.indexOf("msword") != -1)) {
     outidea = inidea.replace(" Type is ", "<img onclick=window.open(' . "'" . '" + parts[0] + "' . "'" . ',' . "'" . '_blank' . "'" . '); width=45 height=45 src=' . "'" . '" + doci + "' . "'" . ' title=' . "'" . '" + parts[0] + "' . "'" . ' /> Type is ");
   } else if (inidea.indexOf("application/") != -1) {
     outidea = inidea.replace(" Type is ", "<img onclick=window.open(' . "'" . '" + parts[0] + "' . "'" . ',' . "'" . '_blank' . "'" . '); width=45 height=45 src=' . "'" . '" + appi + "' . "'" . ' title=' . "'" . '" + parts[0] + "' . "'" . ' /> Type is ");
   } else if (inidea.indexOf("image/") != -1) {
     outidea = inidea.replace(" Type is ", "<img onclick=window.open(' . "'" . '" + parts[0] + "' . "'" . ',' . "'" . '_blank' . "'" . '); width=45 height=45 src=' . "'" . '" + parts[0] + "' . "'" . ' title=' . "'" . '" + parts[0] + "' . "'" . ' /> Type is ");
   }
   //alert(outidea);
   return outidea;
 } 
 
function process(infilecontents) {
    if (infilecontents != null) {
         if (1 == 7) { alert(infilecontents); }
         var ourlines = infilecontents.split(String.fromCharCode(10));   
         ';
    if ($deadlinks != "") {
    $outhtml .= '
         if (1 == 1) {
           document.getElementById("flist").value = document.getElementById("flist").value + justhttp(ourlines);
           document.getElementById("dlb").click();
         } else {
         for (var jj=0; jj<ourlines.length; jj++) {
           document.getElementById("dli").src = "./fileinfotable.php?deadlinks=&justreporton=" + encodeURIComponent(ourlines[jj]);
         }
         }
         ';
    } else {
    $outhtml .= '
         var ourwords, ourwordcnt = 0; //infilecontents.split(String.fromCharCode(32)); 
         for (var jjj=0; jjj<ourlines.length; jjj++) {
           ourwords = ourlines[jjj].split(String.fromCharCode(32));
           ourwordcnt = eval(ourwordcnt + ourwords.length); 
         }
         
         if (1 == 2 && ((document.getElementById("file").files[0].type || "n/a").indexOf("image/") != -1 || (document.getElementById("file").files[0].type || "n/a").indexOf("/pdf") != -1 || (document.getElementById("file").files[0].type || "n/a").indexOf("audio/") != -1 || (document.getElementById("file").files[0].type || "n/a").indexOf("video/") != -1 || (document.getElementById("file").files[0].type || "n/a").indexOf("application/") != -1)) {
            window.open(document.getElementById("file").value, "_blank");
            document.getElementById("media").width = "500px";
            document.getElementById("media").height = "500px";
            document.getElementById("media").style.display = "block";
            document.getElementById("media").src = document.getElementById("file").value;
         }
         
         //var myfis = "<br><br><p id=myf align=center>Filename is <strong>" + escape(document.getElementById("file").files[0].mozFullPath + document.getElementById("file").value) + "</strong> ... Type is (" + (document.getElementById("file").files[0].type || "n/a") + ") ... Date is " + (document.getElementById("file").files[0].lastModifiedDate ? document.getElementById("file").files[0].lastModifiedDate.toLocaleDateString() : "n/a") + " ... Size is " + infilecontents.length + " bytes ... Line Count is " + ourlines.length + " ... Word Count is " + ourwords.length + "</p>";
         var myfis = "<br><br><p id=myf align=center>Filename is <strong>" + maybemedia(escape(document.getElementById("file").value) + "</strong> ... Type is (" + (document.getElementById("file").files[0].type || "n/a") + ") ... Date is ") + (document.getElementById("file").files[0].lastModifiedDate ? document.getElementById("file").files[0].lastModifiedDate.toLocaleDateString() : "n/a") + " ... Size is " + infilecontents.length + " bytes ... Line Count is " + ourlines.length + " ... Word Count is " + ourwordcnt + "</p>";
         document.body.innerHTML = document.body.innerHTML + myfis;
         var huh = document.URL.split("?");
         if (huh.length > 1) {
           location.href = huh[0] + "?' . $myfe . '" + decodeURIComponent(myfis);
         } else {
           location.href = document.URL + "?' . $myfe . '" + decodeURIComponent(myfis);
         }
         fcont = infilecontents;  
         ';
    }
    $outhtml .= '
     }    
}

  function nocaret(iinf, lno, jpos, inc) {
    var prenoinc = inc.split("<");
    var noinc = prenoinc[0].split(String.fromCharCode(92));
    if (jpos > 0) return noinc[0].replace("http", "http(" + iinf + "|" + lno + "@" + jpos + ")").replace("HTTP", "HTTP(" + iinf + "|" + lno + "@" + jpos + ")");
    return noinc[0].replace("http", "http(" + iinf + "|" + lno + ")").replace("HTTP", "HTTP(" + iinf + "|" + lno + ")");
  }

  function justhttps(instr, ininfo) {
    //document.title = ininfo;
    if (bigf[bigj] == null || bigf[bigj] == undefined) {
      bigf[bigj] = document.getElementById("file").value;
    }
    return justhttp(instr.split(String.fromCharCode(eval(0 + 10))), bigf[bigj]);  // ininfo);
  }

  function justhttp(inarr, ininf) {
    var outst = "", arec = "", ipos = 0, httparr, ijkh, otherarr, endl = "", qpos = 0;
    bigj = bigj + 1;
    //alert(ininf);
    for (var iq=0; iq<inarr.length; iq++) {
      arec = inarr[iq];
      if (arec.indexOf("http") == 0 || arec.indexOf("HTTP") == 0) {
        endl = "";
        //if (inarr[iq].substring(8).indexOf("/") == -1) endl = "/";
        outst = outst + nocaret(ininf,eval(iq + 1),1,inarr[iq] + endl) + String.fromCharCode(eval(0 + 10));
        arec = "";
      } else if (arec.indexOf("http") == 1 || arec.indexOf("HTTP") == 1) {
        endl = "";
        //if (inarr[iq].replace(inarr[iq].substring(0,1), "").replace(inarr[iq].substring(0,1), "").substring(8).indexOf("/") == -1) endl = "/";
        outst = outst + nocaret(ininf,eval(iq + 1),2,inarr[iq].replace(inarr[iq].substring(0,1), "").replace(inarr[iq].substring(0,1), "")) + endl + String.fromCharCode(eval(0 + 10));
        arec = "";
      } 
      if (arec.indexOf("http") > 1) {
        while (arec.indexOf("http") > 1) {
          qpos = eval(1 + arec.indexOf("http"));
          httparr = arec.split("http");
          for (ijkh=1; ijkh<httparr.length; ijkh++) {
            endl = "";
            otherarr = httparr[ijkh].split(httparr[eval(-1 + ijkh)].substring(eval(-1 + httparr[eval(-1 + ijkh)].length)));
            if (otherarr[0].substring(0,1) != "_") {
            //if (otherarr[0].substring(4).indexOf("/") == -1) endl = "/";
            outst = outst + nocaret(ininf,eval(iq + 1),qpos,"http" + otherarr[0] + endl) + String.fromCharCode(eval(0 + 10));
            }
            arec = arec.replace("http", "xxxx");
          }
        }
      } 
      if (arec.indexOf("HTTP") > 1) {  
        while (arec.indexOf("HTTP") > 1) {
          qpos = eval(1 + arec.indexOf("HTTP"));
          httparr = arec.split("HTTP");
          for (ijkh=1; ijkh<httparr.length; ijkh++) {
            endl = "";
            otherarr = httparr[ijkh].split(httparr[eval(-1 + ijkh)].substring(eval(-1 + httparr[eval(-1 + ijkh)].length)));
            if (otherarr[0].substring(0,1) != "_") {
            //if (otherarr[0].substring(4).indexOf("/") == -1) endl = "/";
            outst = outst + nocaret(ininf,eval(iq + 1),qpos,"HTTP" + otherarr[0] + endl) + String.fromCharCode(eval(0 + 10));
            }
            arec = arec.replace("HTTP", "xxxx");
          }
        }
      }
    }
    //alert(outst);
    return outst;
  }

  function handleFileSelect(evt) {
    var ourcont="";
    var readers = new Array();
    var f;
    var thelines;
    var thewords;
    var files = evt.target.files; // FileList object

    // files is a FileList of File objects. List some properties.
    var output = [];
    var file; // = files[0];
    var start; // = parseInt(opt_startByte) || 0;
    var stop; // = parseInt(opt_stopByte) || file.size - 1;
    var blob; // = file.slice(start, stop + 1);
    

    omyh1 = document.getElementById("myh1");
    
' . $omyh1stuff . '
    
    document.getElementById("list").innerHTML = "";
    try {
     document.getElementById("xlist").innerHTML = "";
    } catch (exx) {
    }
   
    if (document.body.innerHTML.indexOf("my" + "res") == -1) {
      document.body.innerHTML = document.body.innerHTML + "<span id=my" + "res style=display:none;>~" + "~</span>";
    } else {
      prevmy_res = document.getElementById("my" + "res").innerHTML;
      document.getElementById("my" + "res").innerHTML = "~" + "~";
    }
    


    for (var i = 0, f; f = files[i]; i++) {
      bigf[bigf.length] = f.name;
      document.getElementById("fname").value = f.name;
      bigi = eval(1 + i);
      file = f;
      start = 0;
      fcont = "";
      stop = file.size - 1;

      readers[readers.length] = new FileReader();

     if (imgmode == " " && file.type.match(' . "'" . 'image.*' . "'" . ')) {
       imgmode = "y";
     } else if (imgmode == " ") {
       imgmode = "";
     }



      // Only process image files.
     if (imgmode == "y" || file.type.match(' . "'" . 'image.*' . "'" . ') || file.type.indexOf(' . "'" . '/pdf' . "'" . ') != -1 || file.type.indexOf(' . "'" . 'audio/' . "'" . ') != -1 || file.type.indexOf(' . "'" . 'video/' . "'" . ') != -1 || file.type.indexOf(' . "'" . 'application/' . "'" . ') != -1) {
      // Closure to capture the file information.
      readers[readers.length - 1].onload = (function(theFile) {
        return function(e) {
          // Render thumbnail.
          if (document.body.innerHTML.indexOf(' . "'" . '" title="' . "'" . ' + escape(theFile.name) + ' . "'" . "'" . ' ) == -1) {
          var vid=escape(theFile.name).replace(".","");
          var mvid = theFile.name.replace(".","m");
          if (theFile.type.indexOf("image/") != -1 || theFile.type.indexOf("/pdf") != -1 || theFile.type.indexOf("audio/") != -1 || theFile.type.indexOf("video/") != -1 || theFile.type.indexOf("application/") != -1) {
          var span = document.createElement("span");
          var elt = "img";
          if (theFile.type.indexOf("image/") == -1) elt = "iframe";
          if (theFile.type.indexOf("/pdf") != -1) {
            span.innerHTML = [' . "'" . '<a class=pdfa href=#' . "'" . ' + vid + ' . "'" . ' onclick=document.getElementById("' . "'" . ' + vid + ' . "'" . '").style.display="block"; class="thumb" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"><img src=icon_pdf.gif title=Pdf />' . "'" . ' + escape(theFile.name) + ' . "'" . '</a>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("audio/") != -1) {
            span.innerHTML = [' . "'" . '<a class=pdfa href=#' . "'" . ' + vid + ' . "'" . ' onclick=document.getElementById("' . "'" . ' + vid + ' . "'" . '").style.display="block"; class="thumb" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"><img src=icon_external.gif title=Pdf />' . "'" . ' + escape(theFile.name) + ' . "'" . '</a>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("video/") != -1) {
            span.innerHTML = [' . "'" . '<a class=pdfa href=#' . "'" . ' + vid + ' . "'" . ' onclick=document.getElementById("' . "'" . ' + vid + ' . "'" . '").style.display="block"; class="thumb" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"><img src=icon_external.gif title=Pdf />' . "'" . ' + escape(theFile.name) + ' . "'" . '</a>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("application/") != -1 && theFile.type.indexOf("spreadsheet") != -1) {
            span.innerHTML = [' . "'" . '<a class=pdfa href=#' . "'" . ' + vid + ' . "'" . ' onclick=document.getElementById("' . "'" . ' + vid + ' . "'" . '").style.display="block"; class="thumb" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"><img src=icon_xls.gif title=Pdf />' . "'" . ' + escape(theFile.name) + ' . "'" . '</a>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("application/") != -1 && (theFile.type.indexOf("document") != -1 || theFile.type.indexOf("msword") != -1)) {
            span.innerHTML = [' . "'" . '<a class=pdfa href=#' . "'" . ' + vid + ' . "'" . ' onclick=document.getElementById("' . "'" . ' + vid + ' . "'" . '").style.display="block"; class="thumb" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"><img src=icon_doc.gif title=Pdf />' . "'" . ' + escape(theFile.name) + ' . "'" . '</a>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("application/") != -1) {
            span.innerHTML = [' . "'" . '<a class=pdfa href=#' . "'" . ' + vid + ' . "'" . ' onclick=document.getElementById("' . "'" . ' + vid + ' . "'" . '").style.display="block"; class="thumb" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"><img src=icon_popup.gif title=Pdf />' . "'" . ' + escape(theFile.name) + ' . "'" . '</a>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else {
            span.innerHTML = [' . "'" . '<img onclick=document.getElementById("' . "'" . ' + vid + ' . "'" . '").style.display="block"; class="thumb" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"/>' . "'" . '].join(' . "'" . '' . "'" . ');
          }
          document.getElementById(' . "'" . 'imglist' . "'" . ').insertBefore(span, null);
          }
          var xxxx="<p id="' . "" . ' + mvid + ' . "" . '"  align=center>Filename is <strong>" + maybemedia(escape(theFile.name) + "</strong> ... Type is (" + (theFile.type || "n/a") + ") ... Date is ") + (theFile.lastModifiedDate ? theFile.lastModifiedDate.toLocaleDateString() : "n/a") + " ... Size is " + theFile.size + " bytes </p>";
          var span1 = document.createElement("span");
          span1.innerHTML = xxxx;
          document.getElementById(' . "'" . 'imglist' . "'" . ').insertBefore(span1, null);
          if (theFile.type.indexOf("image/") != -1 || theFile.type.indexOf("/pdf") != -1 || theFile.type.indexOf("audio/") != -1 || theFile.type.indexOf("video/") != -1 || theFile.type.indexOf("application/") != -1) {
          var span2 = document.createElement("span");
          var elt = "img";
          if (theFile.type.indexOf("image/") == -1) elt = "iframe";
          
          // .xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
          // .docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
          // .ods application/vnd.oasis.opendocument.spreadsheet
          // .odb application/vnd.oasis.opendocument.database
          // .odf application/vnd.oasis.opendocument.formula
          // .pptx application/vnd.openxmlformats-officedocument.presentationml.presentation
          // .doc application/msword
          // .htm* text/html
          
          if (theFile.type.indexOf("/pdf") != -1) {
            span2.innerHTML = [' . "'" . '<iframe class=big id="' . "'" . ' + vid + ' . "'" . '" style="display:none;" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"/>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("audio/") != -1) {
            span2.innerHTML = [' . "'" . '<audio controls=controls autoplay=autoplay class=big id="' . "'" . ' + vid + ' . "'" . '" style="display:none;" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"/>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("video/") != -1) {
            span2.innerHTML = [' . "'" . '<video controls=controls autoplay=autoplay class=big id="' . "'" . ' + vid + ' . "'" . '" style="display:none;" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"/>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else if (theFile.type.indexOf("application/") != -1) {
            span2.innerHTML = [' . "'" . '<iframe class=big id="' . "'" . ' + vid + ' . "'" . '" style="display:none;" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"/>' . "'" . '].join(' . "'" . '' . "'" . ');
          } else {
            span2.innerHTML = [' . "'" . '<img class=big id="' . "'" . ' + vid + ' . "'" . '" style="display:none;" src="' . "'" . ', e.target.result,
                            ' . "'" . '" title="' . "'" . ', escape(theFile.name), ' . "'" . '"/>' . "'" . '].join(' . "'" . '' . "'" . ');
		  }
          document.getElementById(' . "'" . 'imglist' . "'" . ').insertBefore(span2, null);
          }
          }
        };
      })(file);

           readers[readers.length - 1].readAsDataURL(file);
      } else if (imgmode == "y") {
      readers[readers.length - 1].onload = (function(theFile) {
        return function(e) {
          var mvid = theFile.name.replace(".","m");
          var xxxx="<p id="' . "" . ' + mvid + ' . "" . '" align=center>Filename is <strong>" + maybemedia(escape(theFile.name) + "</strong> ... Type is (" + (theFile.type || "n/a") + ") ... Date is ") + (theFile.lastModifiedDate ? theFile.lastModifiedDate.toLocaleDateString() : "n/a") + " ... Size is " + theFile.size + " bytes </p>";
          var span1 = document.createElement("span");
          span1.innerHTML = xxxx;
        };
      })(file);

           readers[readers.length - 1].readAsDataURL(file);
      } else {
      

  
    // If we use onloadend, we need to check the readyState.
    readers[readers.length - 1].onloadend = function(evt) {
      if (evt.target.readyState == FileReader.DONE) { // DONE == 2
        var xfcont=evt.target.result;
        var thoselines = xfcont.split(String.fromCharCode(10)); 
         ';
    if ($deadlinks != "") {
    $outhtml .= '
         if (1 == 1) {
           bigbuffer = bigbuffer + evt.target.result + String.fromCharCode(10);
           document.getElementById("flist").value = document.getElementById("flist").value + justhttps(evt.target.result, document.getElementById("fname").value);
         } 
    ';
     }
    $outhtml .= '
        var thosewordscnt = 0, thosewords = xfcont.split(String.fromCharCode(32)); 

         var ourwords, ourwordcnt = 0; //infilecontents.split(String.fromCharCode(32)); 
         for (var jjjj=0; jjjj<thoselines.length; jjjj++) {
           thosewords = thoselines[jjjj].split(String.fromCharCode(32));
           thosewordscnt = eval(thosewordscnt + thosewords.length); 
         }

        if (document.body.innerHTML.indexOf("~" + "~") == -1) {
          document.body.innerHTML = document.body.innerHTML + "<span id=my" + "res style=display:none;>;" + document.getElementById("fname").value + "~" + thoselines.length + "~" + thosewordscnt + "~" + "~</span>";
        } else {
          document.body.innerHTML = document.body.innerHTML.replace("~" + "~", ";" + document.getElementById("fname").value + "~" + thoselines.length + "~" + thosewordscnt + "~" + "~");
        }
        var sofar = document.getElementById("my" + "res").innerHTML;
        var sofars = sofar.split(";");
        var sofarlw;
        for (var j=1; j<sofars.length; j++) {
          if (sofars[j] != "") {
            sofarlw = sofars[j].split("~");
            document.getElementById("l" + j).innerHTML = sofarlw[1];
            document.getElementById("w" + j).innerHTML = sofarlw[2];
          }
          document.getElementById("prelist").value = encodeURIComponent(document.getElementById("list").innerHTML);
        }
      }
      
    };
      output.push("<li>Filename is <strong>", escape(f.name), "</strong> ... Type is (", f.type || "n/a", ") ... Date is ",
                  f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : "n/a", " ... Size is ", 
                  f.size, " bytes ... Line Count is <span id=l" + bigi + ">", "", "</span> ... Word Count is <span id=w" + bigi + ">", "", "</span>", 
                  "</li>");

      blob = file.slice(start, stop + 1);
      readers[readers.length - 1].readAsText(blob, "UTF-8");
      }  


    }
    document.getElementById("list").innerHTML = "<ul>" + output.join("") + "</ul>";
    document.getElementById("prelist").value = encodeURIComponent(document.getElementById("list").innerHTML);
    doneonce="y";
         ';
    if ($deadlinks != "") {
    $outhtml .= '
         if (1 == 1) {
            if (omyh1.innerHTML.indexOf(" Please wait ") == -1) { omyh1.innerHTML = omyh1.innerHTML + " ... Please wait while we analyze your URLs ... ";  } 
            setTimeout(dlbclick, 5000);
            if (1 == 2) {
            if (document.getElementById("flist").value == "") {
             if (bigbuffer != "" || 1 == 1) alert(document.getElementById("my" + "res").innerHTML + " " + "Please wait while we analyze your URLs ... click OK now please.");
             document.getElementById("flist").value = document.getElementById("flist").value + justhttps(bigbuffer, document.getElementById("my" + "res").innerHTML + prevmy_res);
            }
            bigbuffer="";
            document.getElementById("dlb").click();
            }
         } 
    ';
     }
    $outhtml .= '
  }


</script>
';    
    
    $outhtml .= '<style>
  .thumb {
    height: 75px;
    border: 1px solid #000;
    margin: 10px 5px 0 0;
  }
  .pdfa {
    border: 1px solid yellow;
    margin: 10px 5px 0 0;
  }
  .pdfa:visited {
    border: 1px solid yellow;
    margin: 10px 5px 0 0;
    color: lightgreen;
  }
  .pdfa:hover {
    border: 1px solid yellow;
    margin: 10px 5px 0 0;
    color: yellow;
  }
  .big {
    border: 9px solid pink;
    margin: 10px 5px 0 0;
  }
</style></head>' . "\n";
    if (isset($_POST['flist'])) {
    $outhtml .= "<body style='background-color:yellow;' onload='doonload(); '><input type='hidden' id='fname' name='fname' style='display:none;' value=''></input><iframe id='media' src='javascript:none;' width=1 height=1 style='display:none;'></iframe><iframe id='dli' src='javascript:none;' width=1 height=1 style='display:none;'></iframe><h1 id='myh1' align='center'>" . str_replace("Table", "<a target=_blank href=./fileinfotable.php?deadlinks= title=DeadLinks>Table</a>", str_replace("Report", "<a target=_blank href=./fileinfotable.php title=Information>Report</a>", $title)) . "</h1>";
    $outhtml .= '<form id="myfdl" name="myfdl" style="display:none;" method="POST" action="./fileinfotable.php' . $urlsuffix . '"><input type="hidden" name="myf" id="myf" value=""></input><input type="hidden" name="flist" id="flist" value=""></input><input type="hidden" name="deadlinks" id="deadlinks" value="Report list of dead links of file of Absolute URLs"></input><input onclick="' . $omyh1stuff . '" type="submit" name="dlb" id="dlb" value="DeadLinks"></input></form>';
    //$snapshot = $outhtml . "<p align=center>Please wait while we analyze your URLs ...</p><br>";
    //echo $snapshot;
    //$snapshot = "<div id=dac align=center> " . readandprocess($_POST['flist']) . "</div>";
    $outhtml .= "<p align=center>Please wait while we analyze your URLs ...</p><br>";
    $outhtml .= "<div id=dac align=center> " . readandprocess($_POST['flist']) . "</div>";
    } else {
    $outhtml .= "<body style='background-color:yellow;' onload='doonload();'><input type='hidden' id='fname' name='fname' style='display:none;' value=''></input><iframe id='media' src='javascript:none;' width=1 height=1 style='display:none;'></iframe><iframe id='dli' src='javascript:none;' width=1 height=1 style='display:none;'></iframe><h1 id='myh1' align='center'>" . str_replace("Table", "<a target=_blank href=./fileinfotable.php?deadlinks= title=DeadLinks>Table</a>", str_replace("Report", "<a target=_blank href=./fileinfotable.php title=Information>Report</a>", $title)) . "</h1>";
    $outhtml .= '<form id="myfdl" name="myfdl" style="display:none;" method="POST" action="./fileinfotable.php' . $urlsuffix . '"><input type="hidden" name="myf" id="myf" value=""></input><input type="hidden" name="flist" id="flist" value=""></input><input type="hidden" name="deadlinks" id="deadlinks" value="Report list of dead links of file of Absolute URLs"></input><input onclick="' . $omyh1stuff . '" type="submit" name="dlb" id="dlb" value="DeadLinks"></input></form>';
    //$snapshot = $outhtml;
    }
    $outhtml .= "<div align='center'><form style='background-color:lightgreen;' align='center' border=5 method='POST' action='" . $_SERVER['PHP_SELF'] . $urlsuffix . "'>";
    $outhtml .= "<input type='hidden' name='fsp' id='fsp' value=''></input><br>";
    $outhtml .= "Filepath (or  URL): <input size=120 type='text' name='dir' id='dir' value='" . $dir . "' onblur=' if (this.value.length > 0) {  check(this); }'></input><br><br>";
    $outhtml .= "Filespec (or Name): <input size=120 type='text' name='ext' id='ext' value='" . $fsp . $ext . "'></input><br><br>";
    $outhtml .= "<input onclick='" . $omyh1stuff . "' type='submit' name='xsubmit' id='xsubmit' value='Submit'></input>";
    $outhtml .= "</form></div><div align='center' style='background-color:orange;'><br><br><h2>... or ...</h2>";
    $moi = $_SERVER['PHP_SELF'];
    if (1 == 1) {  // Thanks to http://www.html5rocks.com/en/tutorials/file/dndfiles/
    $outhtml .= '<input onmouseover=" if (doneonce.length > 0) { document.getElementById(presm).click();  } " type="file" id="files" name="files[]" multiple />';
    if (isset($_POST['prelist'])) { $outhtml .= '<div id="xlist" name="xlist">' . urldecode($_POST['prelist']) . '</div><br>' . '<output id="imglist" name="imglist"></output><output id="list" name="list"></output>'; } else { $outhtml .= '<output id="imglist" name="imglist"></output><output id="list" name="list"></output>';  } 
    $outhtml .= '<form id="myfx" name="myfx" style="display:none;" method="POST" action="./fileinfotable.php' . $urlsuffix . '"><input type="hidden" name="prelist" id="prelist" value=""></input><input onclick="' . $omyh1stuff . '" type="submit" name ="sm" id="sm" value="Presubmit" style="display:none;"></input></form></div>';
    if ($deadlinks != "") {
      //$outhtml = $snapshot . '<div align="center" style="background-color:lightgray;"><br><br>';
      $outhtml .= '<div align="center" style="background-color:lightgray;"><br><br>';
    } else {
      $outhtml .= '<div align="center" style="background-color:lightgray;"><br><br><h2>... or ...</h2>';
    }
    $outhtml .= '<input type="file" id="file" name="file" />     <span id="mode" name="mode">' . $mode . '</span>: 
<span class="readBytesButtons">
  <button data-startbyte="0" data-endbyte="4" style="display:none;">1-5</button>
  <button data-startbyte="5" data-endbyte="14" style="display:none;">6-15</button>
  <button data-startbyte="6" data-endbyte="7" style="display:none;">7-8</button>
  <button onclick="readBlob(0,0);" onmouseover=" bigf[bigf.length] = document.getElementById(' . "'" . 'file' . "'" . ').value; document.getElementById(' . "'" . 'myf' . "'" . ').value = document.getElementById(' . "'" . 'file' . "'" . ').value; ">Process</button>
</span>
<div id="byte_range" style="display:none;"></div>
<div id="byte_content" style="display:none;"></div>
';
    } else {
    $outhtml .= '    
      <form style="background-color: #E4E4E4;" action="' . $moi . '" method="post" enctype="multipart/form-data">  
        
      <fieldset align="center">  
           <legend align="center">Browse for local file</legend>  
           <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
           <input style="background-color: yellow;" size="100" type="file" id="browsefile" name="browsefile" onchange="analyze();" />  
      </fieldset>  
      <input style="color: green;display:none;" type="submit" name="submit" value="Browse for File" />  
</form>
';
	}
    $outhtml .= "</div>";    
    $outhtml .= "</body></html>";
   } else {
    $outhtml = "<html><head><title>" . $title . " for " . $dir . $fsp . $ext . "</title></head>\n";
    $dc = "Date";
    $sb = "Size (bytes)";
    $lc = "Lines";
    $wc = "Words";
    if ($urlsuffix != "") {
     $dc = "URL";
     $sb = "Status";
     $lc = "On Line";
     $wc = "At Column";
    }
    if ($dir == "") {
     $outhtml .= "<body style='background-color:yellow;'><h1 align='center'>" . $title . " for " . $dir . $fsp . $ext . "</h1><table style='background-color:lightgreen;' align='center' border=5 cellpadding=12 cellspacing=8><tr style='background-color:lightblue;'>";
     $outhtml .= "<th><a href='./fileinfotable.php" . $urlsuffix . "' title='Another go?'>Filename</a></th><th>" . $dc . "</th><th>" . $sb . "</th><th>" . $lc . "</th><th>" . $wc . "</th></tr>";
    } else {
     $outhtml .= "<body style='background-color:yellow;'><h1 align='center'>" . $title . " for " . $dir . $fsp . $ext . "</h1><table style='background-color:lightgreen;' align='center' border=5 cellpadding=12 cellspacing=8><tr style='background-color:lightblue;'>";
     $outhtml .= "<th>Filename in <a href='./fileinfotable.php" . $urlsuffix . "' title='Another go?'>" . $dir . "</a></th><th>" . $dc . "</th><th>" . $sb . "</th><th>" . $lc . "</th><th>" . $wc . "</th></tr>";
    }
    
    if (strpos($dir . $fsp . $ext, "https:") !== false || strpos($dir . $fsp . $ext, "http:") !== false || strpos($dir . $fsp . $ext, "HTTPS:") !== false || strpos($dir . $fsp . $ext, "HTTP:") !== false) {
      if (url_exists($dir . $fsp . $ext)) {
         $cdt = "";
         $cont = file_get_contents($dir . $fsp . $ext);
         if ($urlsuffix != "") {
         readandprocess($fsp . $ext . "@!~*^@" . $cont);   // new ideas here
		 $outhtml .= "<tr><td>" . str_replace($dir, "", $dir . $fsp . $ext) . "</td><td>" . $urllist . "</td><td>" . $statuslist . "</td><td>" . $linelist . "</td><td>" . $collist . "</td></tr>";
         $urllist = "";
         $statuslist = "";
         $linelist = "";
         $collist = "";
         } else {
         $recs = explode("\n", $cont);
         $words = explode(" ", $cont);
		 $h = get_headers($dir . $fsp . $ext, 1); // Thanks to http://stackoverflow.com/questions/845220/get-the-last-modified-date-of-a-remote-file
         $cdt = "";
         try {
		   $cdt = $h['Last-Modified'];
		 } catch (Exception $exxx) {
		   $cdt = "";
		 }
		 $outhtml .= "<tr><td>" . str_replace($dir, "", $dir . $fsp . $ext) . "</td><td>" . $cdt . "</td><td>" . strlen($cont) . "</td><td>" . count($recs) . "</td><td>" . count($words) . "</td></tr>";
		 }
      }
    } else {
     foreach (glob($dir . $fsp . $ext) as $filename) {
     
      if (url_exists($filename)) {
         if ($urlsuffix != "") {
         readandprocess($filename . "@!~*^@" . file_get_contents($filename));   // new ideas here
		 $outhtml .= "<tr><td>" . str_replace($dir, "", $filename) . "</td><td>" . $urllist . "</td><td>" . $statuslist . "</td><td>" . $linelist . "</td><td>" . $collist . "</td></tr>";
         $urllist = "";
         $statuslist = "";
         $linelist = "";
         $collist = "";
         } else {
        
         $lines = file($filename); 
         $cwords = 0;
         foreach ($lines as $line) {
          $cwords += str_word_count($line);
         }
         $outhtml .= "<tr><td>" . str_replace($dir, "", $filename) . "</td><td>" . date("F d Y H:i:s", filemtime($filename)) . "</td><td>" . filesize($filename) . "</td><td>" . count($lines) . "</td><td>" . $cwords . "</td></tr>";
		 }        
      }
     }
    }
    $outhtml .= "</table></body></html>";
   }
   
   echo $outhtml;
   }
?>
