<?php
// php_calls_pdfimages.php
// RJM Programming
// April, 2023
set_time_limit(1200);

$cbi='';
$followupwhat='';
$olmore='';

if (isset($_POST['pdfunitec'])) {
   $cis=str_replace('+',' ',urldecode($_POST['pdfunitec']));
//file_put_contents('xxx01.xxx01', $cis);
   if (explode(' ', $cis)[0] == 'pdfunite' || explode(' ', $cis)[0] == 'pdfunite.exe') {
//file_put_contents('xxx02.xxx01', $cis);
     $huhs=explode('"', $cis);
//file_put_contents('xxx03.xxx01', $cis);
     if (sizeof($huhs) > 5) {
//file_put_contents('xxx04.xxx01', $cis . ' vs ' . sys_get_temp_dir());
     if (sys_get_temp_dir() == substr($huhs[5], 0, strlen(sys_get_temp_dir()))) {
//file_put_contents('xxx05.xxx01', $cis);
      if (PHP_OS == "Darwin") {
//file_put_contents('xxx06.xxx01', $cis);
       putenv('PATH=/usr/local/bin');
       exec(explode(';',$cis)[0] . ' 2> pdfunite.bad');
//file_put_contents('xxx07.xxx01', $cis);
      } else if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
       exec(explode(';', $cis)[0] . ' 2> pdfunite.bad');
      }
     }
     }
   }   
   exit;
}

if (isset($_POST['rmzip'])) {
   $cis=str_replace('+',' ',urldecode($_POST['rmzip']));
   $precis=explode('-', $cis)[0];
   sleep(120);
   $xx='' . rand(456, 78534432);
   if (file_exists($cis) && strpos(($cis . $xx . '~'), '.zip' . $xx . '~') !== false && strpos($cis, '-') !== false) {
     if (file_exists($precis . '.mp4') && trim($precis) != '') {  unlink($precis . '.mp4');  }
     if (file_exists($precis . '.gif') && trim($precis) != '') {  unlink($precis . '.gif');  }
     if (file_exists($precis . '.pdf') && trim($precis) != '') {  unlink($precis . '.pdf');  }
     unlink($cis);
   }
   exit;
}

if (isset($_GET['inurl'])) {
  $mt="image";
  $mprefix='<img src=';
  $rpdf='pdfcopy-0-local-' . rand(0,5773354) . '.pdf';
  $newp=$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $rpdf;
  $newu="http://" . $_SERVER['SERVER_NAME'] . "" . str_replace("~","",str_replace(":443~","",str_replace(":80~","",(":" . $_SERVER['SERVER_PORT'] . "~")))) . '/' . basename($rpdf);
  $filename=str_replace('file://','',str_replace('+',' ',urldecode($_GET['inurl'])));
  if (file_exists($filename)) {
  $outext=str_replace("jpg","jpeg",strtolower(explode(".", $filename)[-1 + sizeof(explode(".", $filename))]));
  if (strtolower($outext) == 'mp4') { $mt='video'; $mprefix='<video controls autoplay><source src='; }
  if (strtolower($outext) == 'pdf') { 
    if (!file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . explode('.pdf',$rpdf)[0] )) {
      mkdir($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . explode('.pdf',$rpdf)[0] );
      $rpdf=explode('.pdf',$rpdf)[0] . DIRECTORY_SEPARATOR;
      $rpdf.=str_replace(' ','+',basename($filename));
      $newp=$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $rpdf;
      $newu="http://" . $_SERVER['SERVER_NAME'] . "" . str_replace("~","",str_replace(":443~","",str_replace(":80~","",(":" . $_SERVER['SERVER_PORT'] . "~")))) . '/' . $rpdf;
    }
    copy($filename, $newp); 
    $mt='application'; $mprefix='<iframe style=width:100%;height:90%; src='; 
  }
  $datau='data:' . $mt . '/' . $outext . ';base64,' . base64_encode(file_get_contents($filename));
  if (strtolower($outext) == 'pdf') { $datau='./' . $rpdf; }
  $dw=$mprefix . $datau . '></' . str_replace('video', 'source></video', explode(' ',substr($mprefix,1))[0]) . '>';
  if (strtolower($outext) == 'pdf') {   
  sleep(3);
  echo "<html><head><title>" . str_replace('+',' ',basename($filename)) . "</title></head><body onload=\"var woisa=window.open('" . $datau . "#" . str_replace('+',' ',basename($filename)) . "', '_self'); woisa.title='" . basename($filename) . "'; \"></body></html>";
  } else {
  echo "<html><head><title>" . str_replace('+',' ',basename($filename)) . "</title></head><body onload=\"var woisa=window.open('', '_self'); woisa.document.write('" . $dw . "');\"><iframe id=myif style=display:none; src=./php_calls_pdfimages.php?nopdfurl=y></iframe></body></html>";
  }
  }
  exit;
} else if (isset($_GET['nopdfurl'])) {
  sleep(37);
foreach (glob('pdfcopy-0-local-' . '*.pdf') as $filename) {
    try {
    unlink($filename);
    } catch (Exception $werty) { }
}
foreach (glob('pdfcopy-0-local-*' . DIRECTORY_SEPARATOR . '*.pdf') as $filename) {
    try {
    unlink($filename);
    } catch (Exception $werty) { }
    try {
    rmdir(explode(basename($filename), $filename)[0]);
    } catch (Exception $werty) { }
}
exit;
}

$pdfprotocol='file://';

function oururlencode($whata) {
  global $pdfprotocol;
  if (strpos('~' . strtolower($whata), '~http') !== false) { return str_replace(urlencode(DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, urlencode($whata));  }
  $newwhata=str_replace($_SERVER['DOCUMENT_ROOT'], "http://" . $_SERVER['SERVER_NAME'] . "" . str_replace("~","",str_replace(":443~","",str_replace(":80~","",(":" . $_SERVER['SERVER_PORT'] . "~")))), $whata);
  if ($newwhata == $whata || 1 == 1) {
     //file_put_contents('xaa.xaa', 'whata=' . $whata . ' and retval=' . urlencode($whata) . ' versus ' . str_replace(urlencode(DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, urlencode($whata)));
     if (1 == 1) {
     $pdfprotocol='file://';
     $pdfprotocol='./';
     return 'php_calls_pdfimages.php?inurl=' . 'file://' . str_replace(urlencode(DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, urlencode($whata));
     } else {
     $pdfprotocol='file://';
     return str_replace(urlencode(DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, urlencode($whata));
     //return urlencode($whata);
     }
  } 
  $pdfprotocol=explode($_SERVER['SERVER_NAME'], $newwhata)[0];
  return str_replace(urlencode(DIRECTORY_SEPARATOR), '/', str_replace(urlencode('/'), '/', urlencode(explode($pdfprotocol, $newwhata)[1])));
}

function ourtouch($fp1, $fp2) {
  if (file_exists($fp1)) {
     file_put_contents($fp1, file_get_contents($fp1) . '                      ');
     //file_put_contents('xx0.xx0', file_get_contents($fp1));
     return filesize($fp1);
  }
  return '';
}

function ourunlink($what) {
   global $followupwhat, $olmore;
   $huhpis=explode('.', $what);
foreach (glob($huhpis[0] . '-*') as $filename) {
    try {
    if (strpos($filename, '.zip') !== false && $followupwhat == '') { // && (isset($_GET['pdfbighp']) || isset($_POST['pdfbighp']))) {
       $followupwhat=$filename;
       $olmore=" parent.rmzipit('" . $followupwhat . "'); ";
    } else if (strpos($filename, '.zip') !== false) { // && (isset($_GET['pdfbighp']) || isset($_POST['pdfbighp']))) {
       $followupwhat=$filename;
    } else {
       unlink($filename);
    }
    } catch (Exception $werty) { }
}
if (isset($_GET['pdfbighp'])) {
  if (file_exists(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['pdfbighp'])))) {
foreach (glob(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . DIRECTORY_SEPARATOR . '*.*') as $filename) {
    try {
    unlink($filename);
    } catch (Exception $werty) { }
}
    exec('rmdir ' . rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['pdfbighp'])));
  }
} else if (isset($_POST['pdfbighp'])) {
  if (file_exists(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_POST['pdfbighp'])))) {
foreach (glob(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_POST['pdfbighp'])) . DIRECTORY_SEPARATOR . '*.*') as $filename) {
    try {
    unlink($filename);
    } catch (Exception $werty) { }
}
    exec('rmdir ' . rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_POST['pdfbighp'])));
  }
}
   unlink($what);
}

$pdfh='';
$pdfbigh='';


$defdef='';
$autoplay='';
$fextra='';
$infile='"input_pdf.pdf"';
$pathp='.' . DIRECTORY_SEPARATOR;
if (isset($_GET['inpath'])) {
  if (trim(str_replace('+',' ',urldecode($_GET['inpath']))) != '') {
    $pathp=str_replace('+',' ',urldecode($_GET['inpath']));
    if (substr(strrev($pathp),0,1) != DIRECTORY_SEPARATOR) {
      $pathp.=DIRECTORY_SEPARATOR;
    }
  }
} else if (isset($_POST['inpath'])) {
  if (trim(str_replace('+',' ',urldecode($_POST['inpath']))) != '') {
    $pathp=str_replace('+',' ',urldecode($_POST['inpath']));
    if (substr(strrev($pathp),0,1) != DIRECTORY_SEPARATOR) {
      $pathp.=DIRECTORY_SEPARATOR;
    }
  }
}

if (isset($_GET['convertthis'])) {
$cbi='&nbsp;<iframe scrolling="no" frameborder="0" id="cbix" data-style="border-top:1px solid black;border-bottom:1px solid black;border-left:2px solid yellow;border-right:1px solid yellow;" style="display:inline-block;width:133px;height:239px;margin-top:-221px;z-index:-78;" src="HTMLCSS/client_browsing.htm?d=902796484271&wording=Pdfimages%20media%2E%20"></iframe>';
  $infile='"' . $pathp . str_replace('+',' ',urldecode($_GET['convertthis'])) . '"';
  $fextra='<font color="black" size="1">&nbsp;<a onclick="document.getElementById(' . "'mysif'" . ').src=document.URL.split(String.fromCharCode(63))[0].split(String.fromCharCode(35))[0] + ' . "'" . '?nopdfurl=y' . "'" . ';" target="_blank" title="Original PDF is ' . str_replace('"',"'",$infile) . '" href="' . $pdfprotocol . str_replace('+','%20',oururlencode(str_replace('"','',$infile))) . '">' . basename(str_replace('"','',$infile)) . '</a></font>';
//file_put_contents('xa.xa', $fextra);
} else if (isset($_POST['convertthis'])) {
$cbi='&nbsp;<iframe scrolling="no" frameborder="0" id="cbix" data-style="border-top:1px solid black;border-bottom:1px solid black;border-left:2px solid yellow;border-right:1px solid yellow;" style="display:inline-block;width:133px;height:239px;margin-top:-221px;z-index:-78;" src="HTMLCSS/client_browsing.htm?d=975964842271&wording=Pdfimages%20media%2E%20"></iframe>';
  $infile='"' . $pathp . str_replace('+',' ',urldecode($_POST['convertthis'])) . '"';
  $fextra='<font color="black" size="1">&nbsp;<a onclick="document.getElementById(' . "'mysif'" . ').src=document.URL.split(String.fromCharCode(63))[0].split(String.fromCharCode(35))[0] + ' . "'" . '?nopdfurl=y' . "'" . ';" target="_blank" title="Original PDF is ' . str_replace('"',"'",$infile) . '" href="' . $pdfprotocol . str_replace('+','%20',oururlencode(str_replace('"','',$infile))) . '">' . basename(str_replace('"','',$infile)) . '</a></font>';
//file_put_contents('xa2.xa2', $fextra);
}


$olstuff='';

$comparep='';
$comparev='';
$comparea='';
$komparep='';
$komparev='';
$komparea='';
if (isset($_POST['dela']) && !isset($_POST['touch'])) {
       if (file_exists(basename(str_replace('+',' ', urldecode($_POST['dela']))))) {
         $comparea=date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_POST['dela'])))));
         $komparea=filesize(basename(str_replace('+',' ', urldecode($_POST['dela']))));
       }
}
if (isset($_POST['delv']) && !isset($_POST['touch'])) {
       $_GET['delv']='video.bad';
       //if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delv']))))) {
       //  $comparev=date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_POST['delv'])))));
       //  $komparev=filesize(basename(str_replace('+',' ', urldecode($_POST['delv']))));
       //}
       if (file_exists(basename(str_replace('+',' ', urldecode($_GET['delv']))))) {
         $comparev=date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_GET['delv'])))));
         $komparev=filesize(basename(str_replace('+',' ', urldecode($_GET['delv']))));
       }
}
if (isset($_POST['delp']) && !isset($_POST['touch'])) {
       if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delp']))))) {
         $comparep=date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_POST['delp'])))));
         $komparep=filesize(basename(str_replace('+',' ', urldecode($_POST['delp']))));
       }
}
if (isset($_POST['delh']) && !isset($_POST['touch'])) {
       if (file_exists('pdftohtml.bad')) {
         $comparep=date("F d Y H:i:s.", filemtime('pdftohtml.bad'));
         $komparep=filesize('pdftohtml.bad');
       }
}
if (isset($_POST['delx']) && !isset($_POST['touch'])) {
       if (file_exists('pdftoxml.bad')) {
         $comparep=date("F d Y H:i:s.", filemtime('pdftoxml.bad'));
         $komparep=filesize('pdftoxml.bad');
       }
}

if (isset($_POST['delv'])) {
  if ($_POST['delv'] != '') {
    $_GET['delv']='video.bad';
    if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delv']))))) {
      if (strpos(strtolower(str_replace('+',' ', urldecode($_POST['delv'])) . "?"), ".mp4?") !== false) {
       if (isset($_POST['touch'])) {
             //file_put_contents('xx0.xx0', 'y');
         if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delv']))))) {
           if (PHP_OS == "Darwin" || 1 == 1) {
             //file_put_contents('xx1.xx1', filesize(basename(str_replace('+',' ', urldecode($_GET['delv'])))) . '/' . date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_GET['delv']))))) . ' ');
             //$time = time()+15000;
             $xx=ourtouch(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename(str_replace('+',' ', urldecode($_GET['delv']))), null); //exec("touch " . basename(str_replace('+',' ', urldecode($_POST['delv']))));
             //sleep(3);
             //file_put_contents('xx1.xx1', file_get_contents('xx1.xx1') . ' ' . $xx . '  ' .  filesize(basename(str_replace('+',' ', urldecode($_GET['delv'])))) . '/' .date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_GET['delv']))))) . ' ');
             if (!isset($_POST['delp']) && !isset($_POST['dela']) && !isset($_POST['delh']) && !isset($_POST['delx'])) {
               exit;
             }
           } else {
             if (!isset($_POST['delp']) && !isset($_POST['dela']) && !isset($_POST['delh']) && !isset($_POST['delx'])) {
               exit;
             }
           }
         }
       } else {
       //$comparev='';
       //if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delv']))))) {
       //  $comparev=date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_POST['delv'])))));
       //}
       sleep(20);
       if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delv']))))) {
         if ($comparev == 'HUH' || ($komparev == filesize(basename(str_replace('+',' ', urldecode($_GET['delv'])))) && $comparev == date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_GET['delv']))))))) {
             //file_put_contents('xxx1.xxx1', $comparev);
           ourunlink(basename(str_replace('+',' ', urldecode($_POST['delv']))));
           $olstuff.=" if (parent.document.getElementById('vemail')) { parent.document.getElementById('vemail').style.display='none'; }  if (parent.document.getElementById('vsms')) { parent.document.getElementById('vsms').style.display='none'; } ";
         }
       }
       }
      }
    }
    if (!isset($_POST['delp']) && !isset($_POST['dela']) && !isset($_POST['delh']) && !isset($_POST['delx'])) {
      if ($olstuff != '') {
        echo "<html><body onload=\"" . $olstuff . $olmore . "\"></body></html>";
      }
      exit;
    }
  }
}

if (isset($_POST['dela'])) {
  if ($_POST['dela'] != '') {
    if (file_exists(basename(str_replace('+',' ', urldecode($_POST['dela']))))) {
      if (strpos(strtolower(str_replace('+',' ', urldecode($_POST['dela'])) . "?"), ".gif?") !== false) {
       if (isset($_POST['touch'])) {
             //file_put_contents('xx2.xx2', 'y');
         if (file_exists(basename(str_replace('+',' ', urldecode($_POST['dela']))))) {
           if (PHP_OS == "Darwin" || 1 == 1) {
             //file_put_contents('xx3.xx3', 'y');
             $time = time()+15000;
             touch(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename(str_replace('+',' ', urldecode($_POST['dela']))), null); //exec("touch " . basename(str_replace('+',' ', urldecode($_POST['dela']))));
             if (!isset($_POST['delp']) && !isset($_POST['delh']) && !isset($_POST['delx'])) {
               exit;
             }
           } else {
             if (!isset($_POST['delp']) && !isset($_POST['delh']) && !isset($_POST['delx'])) {
               exit;
             }
           }
         }
       } else {
       //$comparea='';
       //if (file_exists(basename(str_replace('+',' ', urldecode($_POST['dela']))))) {
       //  $comparea=date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_POST['dela'])))));
       //}
       sleep(20);
       if (file_exists(basename(str_replace('+',' ', urldecode($_POST['dela']))))) {
         if ($comparea == 'HUH' || $comparea == date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_POST['dela'])))))) {
             //file_put_contents('xxx3.xxx3', $comparea);
           ourunlink(basename(str_replace('+',' ', urldecode($_POST['dela']))));
           $olstuff.=" if (parent.document.getElementById('aemail')) { parent.document.getElementById('aemail').style.display='none'; }  if (parent.document.getElementById('asms')) { parent.document.getElementById('asms').style.display='none'; } ";
         }
       }
       }
      }
    }
    if (!isset($_POST['delp'])) {
      if ($olstuff != '') {
        echo "<html><body onload=\"" . $olstuff . $olmore . "\"></body></html>";
      }
      exit;
    }
  }
}


if (isset($_POST['delp'])) {
  if ($_POST['delp'] != '') {
       if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delp']))))) {
      if (strpos(strtolower(str_replace('+',' ', urldecode($_POST['delp'])) . "?"), ".pdf?") !== false) {
       if (isset($_POST['touch'])) {
             //file_put_contents('xx4.xx4', 'y');
         if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delp']))))) {
           if (PHP_OS == "Darwin" || 1 == 1) {
             //file_put_contents('xx5.xx5', 'y');
             $time = time()+15000;
             touch(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename(str_replace('+',' ', urldecode($_POST['delp']))), null); //exec("touch " . basename(str_replace('+',' ', urldecode($_POST['delp']))));
             if (!isset($_POST['delh']) && !isset($_POST['delx'])) {
               exit;
             }
           } else {
             if (!isset($_POST['delh']) && !isset($_POST['delx'])) {
               exit;
             }
           }
         }
       } else {
       //$comparep='';
       //if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delp']))))) {
       //  $comparep=date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_POST['delp'])))));
       //}
       sleep(20);
       if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delp']))))) {
         if ($comparep == 'HUH' || $comparep == date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_POST['delp'])))))) {
             //file_put_contents('xxx5.xxx5', $comparep);
           ourunlink(basename(str_replace('+',' ', urldecode($_POST['delp']))));
           $olstuff.=" if (parent.document.getElementById('pemail')) { parent.document.getElementById('pemail').style.display='none'; }  if (parent.document.getElementById('psms')) { parent.document.getElementById('psms').style.display='none'; } ";
         }
       }
      }
      }
    }
    if ($olstuff != '') {
        echo "<html><body onload=\"" . $olstuff . $olmore . "\"></body></html>";
    }
    exit;
  }
}


if (isset($_POST['delh'])) {
  if ($_POST['delh'] != '') {
       $_POST['delh']='pdftohtml.bad';
       if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delh']))))) {
      if (strpos(strtolower(str_replace('+',' ', urldecode($_POST['delh'])) . "?"), ".pdf?") !== false) {
       if (isset($_POST['touch'])) {
             //file_put_contents('xx4.xx4', 'y');
         if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delh']))))) {
           if (PHP_OS == "Darwin" || 1 == 1) {
             //file_put_contents('xx5.xx5', 'y');
             $time = time()+15000;
             touch(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename(str_replace('+',' ', urldecode($_POST['delh']))), null); //exec("touch " . basename(str_replace('+',' ', urldecode($_POST['delh']))));
             if (!isset($_POST['delx'])) {
               exit;
             }
           } else {
             if (!isset($_POST['delx'])) {
               exit;
             }
           }
         }
       } else {
       //$comparep='';
       //if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delh']))))) {
       //  $comparep=date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_POST['delh'])))));
       //}
       sleep(20);
       if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delh']))))) {
         if ($comparep == 'HUH' || $comparep == date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_POST['delh'])))))) {
             //file_put_contents('xxx5.xxx5', $comparep);
           ourunlink(basename(str_replace('+',' ', urldecode($_POST['delh']))));
           $olstuff.=" if (parent.document.getElementById('hemail')) { parent.document.getElementById('hemail').style.display='none'; }  if (parent.document.getElementById('hsms')) { parent.document.getElementById('hsms').style.display='none'; } ";
         }
       }
      }
      }
    }
    if ($olstuff != '') {
        echo "<html><body onload=\"" . $olstuff . $olmore . "\"></body></html>";
    }
    exit;
  }
}

if (isset($_POST['delx'])) {
  if ($_POST['delx'] != '') {
       $_POST['delx']='pdftoxml.bad';
       if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delx']))))) {
      if (strpos(strtolower(str_replace('+',' ', urldecode($_POST['delx'])) . "?"), ".pdf?") !== false) {
       if (isset($_POST['touch'])) {
             //file_put_contents('xx4.xx4', 'y');
         if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delx']))))) {
           if (PHP_OS == "Darwin" || 1 == 1) {
             //file_put_contents('xx5.xx5', 'y');
             $time = time()+15000;
             touch(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename(str_replace('+',' ', urldecode($_POST['delx']))), null); //exec("touch " . basename(str_replace('+',' ', urldecode($_POST['delx']))));
             if (1 == 1) {
               exit;
             }
           } else {
             if (1 == 1) {
               exit;
             }
           }
         }
       } else {
       //$comparep='';
       //if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delx']))))) {
       //  $comparep=date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_POST['delx'])))));
       //}
       sleep(20);
       if (file_exists(basename(str_replace('+',' ', urldecode($_POST['delx']))))) {
         if ($comparep == 'HUH' || $comparep == date("F d Y H:i:s.", filemtime(basename(str_replace('+',' ', urldecode($_POST['delx'])))))) {
             //file_put_contents('xxx5.xxx5', $comparep);
           ourunlink(basename(str_replace('+',' ', urldecode($_POST['delx']))));
           $olstuff.=" if (parent.document.getElementById('xemail')) { parent.document.getElementById('xemail').style.display='none'; }  if (parent.document.getElementById('xsms')) { parent.document.getElementById('xsms').style.display='none'; } ";
         }
       }
      }
      }
    }
    if ($olstuff != '') {
        echo "<html><body onload=\"" . $olstuff . $olmore . "\"></body></html>";
    }
    exit;
  }
}

$vsw=0;
$vw=720;
$vh=540;
$dovideo=false;
$doag=false;
$dopdf=false;
$dohtml=false;
$doxml=false;
$sparepdf="";

if (isset($_GET['dovideo']) || isset($_POST['dovideo'])) {
  $dovideo=true;
} 
if (isset($_GET['doag']) || isset($_POST['doag'])) {
  $doag=true;
}
if (isset($_GET['dopdf']) || isset($_POST['dopdf'])) {
  $dopdf=true;
}
if (isset($_GET['dohtml']) || isset($_POST['dohtml'])) {
  $dohtml=true;
}
if (isset($_GET['doxml']) || isset($_POST['doxml'])) {
  $doxml=true;
}

$vsw=0;
$vw=720;
$vh=540;
if (isset($_GET['sw'])) {
  $vsw=intval($_GET['sw']);
  $vh=(540 * (720 / ($vsw * 0.46)));
  $vw=($vsw * 0.46);
  $vh=explode(".", "$vh")[0];
  $vh /= 2; 
  $vh=explode(".", "$vh")[0];
  $vh *= 2; 
  $vh=explode(".", "$vh")[0];
  $vw=explode(".", "$vw")[0]; 
  $vw /= 2; 
  $vw=explode(".", "$vw")[0];
  $vw *= 2; 
  $vh=intval("$vh");
  $vw=intval("$vw");
  //echo $vh . ',' . $vw . ' via ' . $vsw;
  //exit;
} else if (isset($_POST['sw'])) {
  $vsw=intval($_POST['sw']);
  $vh=(540 * (720 / ($vsw * 0.46)));
  $vw=($vsw * 0.46);
  $vh=explode(".", "$vh")[0];
  $vh /= 2; 
  $vh=explode(".", "$vh")[0];
  $vh *= 2; 
  $vh=explode(".", "$vh")[0];
  $vw=explode(".", "$vw")[0]; 
  $vw /= 2; 
  $vw=explode(".", "$vw")[0];
  $vw *= 2; 
  $vh=intval("$vh");
  $vw=intval("$vw");
  //echo $vh . ',' . $vw . ' via ' . $vsw;
  //exit;
}

if (isset($_GET['install'])) {
   if ($_GET['install'] == 'pdfimages') {
    if (PHP_OS == "Darwin") {
    putenv('PATH=/usr/local/bin');
    $x="<p>Regarding ...<br><br>brew install popper<br><br>If errors below, you should try command above, yourself, on command line ...<br><br><br>";
    $x.=shell_exec('brew install poppler 2> huh.jnk');
     if (file_exists('huhjunk.jnk')) {
       $x.=file_get_contents('huhjnk.jnk');
       unlink('huh.jnk');
     }
     echo "<html><body><pre>" . $x . "</pre></body></html>";
     } else if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
     $x="<p>Regarding ...<br><br>sudo apt-get update <br>sudo apt-get install poppler-utils<br><br>If errors below, you should try commands above, yourself, on command line ...<br><br><br>";
     $x.=shell_exec('sudo apt-get update');
     $x.=shell_exec('sudo apt-get install poppler-utils');
     echo "<html><body><pre>" . $x . "</pre></body></html>";
     }
   } else if ($_GET['install'] == 'ffmpeg') {
    if (PHP_OS == "Darwin") {
    putenv('PATH=/usr/local/bin');
    $x="<p>Regarding ...<br><br>brew install ffmpeg<br><br>If errors below, you should try command above, yourself, on command line ...<br><br><br>";
    $x.=shell_exec('brew install ffmpeg 2> huh.jnk');
     if (file_exists('huhjunk.jnk')) {
       $x.=file_get_contents('huhjnk.jnk');
       unlink('huh.jnk');
     }
     echo "<html><body><pre>" . $x . "</pre></body></html>";
     } else if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
     $x="<p>Regarding ...<br><br>sudo apt update -y <br>sudo apt install ffmpeg -y<br><br>If errors below, you should try commands above, yourself, on command line ...<br><br><br>";
     $x.=shell_exec('sudo apt update -y');
     $x.=shell_exec('sudo apt install ffmpeg -y');
     echo "<html><body><pre>" . $x . "</pre></body></html>";
     }
   } else if ($_GET['install'] == 'imagemagick') {
    if (PHP_OS == "Darwin") {
    putenv('PATH=/usr/local/bin');
    $x="<p>Regarding ...<br><br>brew install imagemagick<br><br>If errors below, you should try command above, yourself, on command line ...<br><br><br>";
    $x.=shell_exec('brew install imagemagick 2> huh.jnk');
     if (file_exists('huhjunk.jnk')) {
       $x.=file_get_contents('huhjnk.jnk');
       unlink('huh.jnk');
     }
     echo "<html><body><pre>" . $x . "</pre></body></html>";
     } else if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
     $x="<p>Regarding ...<br><br>sudo apt update<br>sudo apt install imagemagick<br><br>If errors below, you should try commands above, yourself, on command line ...<br><br><br>";
     $x.=shell_exec('sudo apt update');
     $x.=shell_exec('sudo apt install imagemagick');
     echo "<html><body><pre>" . $x . "</pre></body></html>";
     }
   }
   exit;
}
if (isset($_POST['install'])) {
   if ($_POST['install'] == 'pdfimages') {
    if (PHP_OS == "Darwin") {
    putenv('PATH=/usr/local/bin');
    $x="<p>Regarding ...<br><br>brew install popper<br><br>If errors below, you should try command above, yourself, on command line ...<br><br><br>";
    $x.=shell_exec('brew install poppler 2> huh.jnk');
     if (file_exists('huhjunk.jnk')) {
       $x.=file_get_contents('huhjnk.jnk');
       unlink('huh.jnk');
     }
     echo "<html><body><pre>" . $x . "</pre></body></html>";
     } else if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
     $x="<p>Regarding ...<br><br>sudo apt-get update <br>sudo apt-get install poppler-utils<br><br>If errors below, you should try commands above, yourself, on command line ...<br><br><br>";
     $x.=shell_exec('sudo apt-get update');
     $x.=shell_exec('sudo apt-get install poppler-utils');
     echo "<html><body><pre>" . $x . "</pre></body></html>";
     }
   } else if ($_POST['install'] == 'ffmpeg') {
    if (PHP_OS == "Darwin") {
    putenv('PATH=/usr/local/bin');
    $x="<p>Regarding ...<br><br>brew install ffmpeg<br><br>If errors below, you should try command above, yourself, on command line ...<br><br><br>";
    $x.=shell_exec('brew install ffmpeg 2> huh.jnk');
     if (file_exists('huhjunk.jnk')) {
       $x.=file_get_contents('huhjnk.jnk');
       unlink('huh.jnk');
     }
     echo "<html><body><pre>" . $x . "</pre></body></html>";
     } else if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
     $x="<p>Regarding ...<br><br>sudo apt update -y <br>sudo apt install ffmpeg -y<br><br>If errors below, you should try commands above, yourself, on command line ...<br><br><br>";
     $x.=shell_exec('sudo apt update -y');
     $x.=shell_exec('sudo apt install ffmpeg -y');
     echo "<html><body><pre>" . $x . "</pre></body></html>";
     }
   } else if ($_POST['install'] == 'imagemagick') {
    if (PHP_OS == "Darwin") {
    putenv('PATH=/usr/local/bin');
    $x="<p>Regarding ...<br><br>brew install imagemagick<br><br>If errors below, you should try command above, yourself, on command line ...<br><br><br>";
    $x.=shell_exec('brew install imagemagick 2> huh.jnk');
     if (file_exists('huhjunk.jnk')) {
       $x.=file_get_contents('huhjnk.jnk');
       unlink('huh.jnk');
     }
     echo "<html><body><pre>" . $x . "</pre></body></html>";
     } else if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
     $x="<p>Regarding ...<br><br>sudo apt update<br>sudo apt install imagemagick<br><br>If errors below, you should try commands above, yourself, on command line ...<br><br><br>";
     $x.=shell_exec('sudo apt update');
     $x.=shell_exec('sudo apt install imagemagick');
     echo "<html><body><pre>" . $x . "</pre></body></html>";
     }
   }
   exit;
}


$filepath='';
$rest="<iframe src=./php_calls_pdfimages.php frameborder=0 style='width:100%;height:1200px;'></iframe>";
$restfrom="<!--table id='thetable'><tbody><tr><td><iframe scrolling='no' onload='iifopen(this);' id='cbi' frameborder='0' style='width:173px;height:228px;margin-top:-184px;' src='/HTMLCSS/client_browsing.htm?d=312015626826&wording=Pdfimages%20images%2E%20'></iframe></td><td id='lstd'></td></tr></tbody></table>
<p id='myp'> ... or ...</p>
<hr id='hr1'></hr>
<br><br>
<form method=POST action=./php_calls_pdfimages.php>
<input title='Path' name='inpath' style='display:inline-block;width:50%;' type='text' id='path' value='' placeholder='Optional input path'><br><br>
<input type='text' data-onblur=\"if (document.URL.toLowerCase().indexOf('rjmprogramming.com.au') != -1) { this.value=''; } else { assessit(this.value); }\" style='width:45%;display:inline-block;' title='Use + (perhaps just by itself) rather than comma to define a list that results in one output file for concatenated or merged media.  Use - to flatten out an Animated GIF or video or PDF.' placeholder='Input PDF file' id='thewords' name='convertthis' value=''><span id=sappend></span><br><br>
<input type=hidden name=sw id=sw value=0></input><input type=hidden name=\"delp\" id=\"delp\" value=\"\"></input><input title='Output prefix' name='outprefix' style='display:inline-block;width:50%;' type='text' id='outpath' value='' placeholder='Optional output *.jpg file prefix [ideas] ... fully capitalize to retain'>&nbsp;<input style=display:inline-block; type=checkbox checked name=dovideo id=dovideo>Video</input>&nbsp;<input style=display:inline-block; type=checkbox checked name=doag id=doag>Animated GIF</input>&nbsp;<input type=checkbox style=display:inline-block; name=dopdf id=dopdf>Image PDF</input>&nbsp;<input type=checkbox style=display:inline-block; name=dohtml id=dohtml>HTML</input>&nbsp;<input type=checkbox style=display:inline-block; name=doxml id=doxml>XML</input><input type=hidden name=pdfbighp id=pdfbighp value=pdftohtml_" . rand(123, 15678956) . "></input><br><br>
<input onclick=\"this.style.cursor='progress'; this.style.border='3px dashed orange'; boo=this; setTimeout(booit, 3000);\" id=mysbut type=submit value='Extract Images (and maybe Create Video and/or Animated GIF and/or Image PDF and/or HTML and/or XML) From ...' style='background-color:yellow;'></input>
</form>
<div id='dpf' style='display:none;'></div>
<div id='dimap'></div>
<div title=' ' id=justputpdfpath style=display:none;></div>
<div title='' id=justputpdffilename style=display:none;></div>
<div title='' id=justputpdffilesize style=display:none;></div>
<iframe style='display:none;' id='gifif' name='gifif' src='//www.rjmprogramming.com.au/About_Us.html'></iframe></div-->";
$restto="<br><br><br><br><br><br><br><br><br><br><table id='thetable'><tbody><tr><td><iframe scrolling='no' onload='iifopen(this);' id='cbi' frameborder='0' style='width:173px;height:228px;margin-top:-184px;' src='/HTMLCSS/client_browsing.htm?d=312310562686&wording=Pdfimages%20images%2E%20'></iframe></td><td id='lstd'></td></tr></tbody></table>
<p id='myp'> ... or ...</p>
<hr id='hr1'></hr>
<br><br>
<form method=POST action=./php_calls_pdfimages.php>
<input title='Path' name='inpath' style='display:inline-block;width:50%;' type='text' id='path' value='' placeholder='Optional input path'><br><br>
<input type='text' data-onblur=\"if (document.URL.toLowerCase().indexOf('rjmprogramming.com.au') != -1) { this.value=''; } else { assessit(this.value); }\" style='width:45%;display:inline-block;' title='Use + (perhaps just by itself) rather than comma to define a list that results in one output file for concatenated or merged media.  Use - to flatten out an Animated GIF or video or PDF.' placeholder='Input PDF file' id='thewords' name='convertthis' value=''><span id=sappend></span><br><br>
<input type=hidden name=sw id=sw value=0></input><input type=hidden name=\"delp\" id=\"delp\" value=\"\"></input><input title='Output prefix' name='outprefix' style='display:inline-block;width:50%;' type='text' id='outpath' value='' placeholder='Optional output *.jpg file prefix [ideas] ... fully capitalize to retain'>&nbsp;<input style=display:inline-block; type=checkbox checked name=dovideo id=dovideo>Video</input>&nbsp;<input style=display:inline-block; type=checkbox checked name=doag id=doag>Animated GIF</input>&nbsp;<input type=checkbox style=display:inline-block; name=dopdf id=dopdf>Image PDF</input>&nbsp;<input type=checkbox style=display:inline-block; name=dohtml id=dohtml>HTML</input>&nbsp;<input type=checkbox style=display:inline-block; name=doxml id=doxml>XML</input><input type=hidden name=pdfbighp id=pdfbighp value=pdftohtml_" . rand(123, 15678956) . "></input><br><br>
<input onclick=\"this.style.cursor='progress'; this.style.border='3px dashed orange'; boo=this; setTimeout(booit, 3000);\" id=mysbut type=submit value='Extract Images (and maybe Create Video and/or Animated GIF and/or Image PDF and/or HTML and/or XML) From ...' style='background-color:yellow;'></input>
</form>
<div id='dpf' style='display:none;'></div>
<div id='dimap'></div>
<div title=' ' id=justputpdfpath style=display:none;></div>
<div title='' id=justputpdffilename style=display:none;></div>
<div title='' id=justputpdffilesize style=display:none;></div>
<iframe style='display:none;' id='gifif' name='gifif' src='//www.rjmprogramming.com.au/About_Us.html'></iframe></div>";

function rsearch($folder, $pattern, $size) { // thanks, anyway, to https://stackoverflow.com/questions/17160696/php-glob-scan-in-subfolders-for-a-file
    $didea='';
    if (PHP_OS == "Darwin") {
      //file_put_contents("x.ksh", "find " . $folder . " -type f -name \"" . $pattern . "\" 2> /dev/null -exec wc -c {} + | egrep '^ " . $size . " ' | sed '/ " . $size . " /s///g'");
      if ($folder == DIRECTORY_SEPARATOR) {
        $didea=shell_exec("find \$HOME/Downloads -type f -name \"" . $pattern . "\" 2> /dev/null -exec wc -c {} + | egrep '^ " . $size . " ' | sed '/ " . $size . " /s///g'");
      //file_put_contents("xx.ksh", $didea);
        if ($didea != '') { return $didea; }
        $didea=shell_exec("find " . rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR  . " -type f -name \"" . $pattern . "\" 2> /dev/null -exec wc -c {} + | egrep '^ " . $size . " ' | sed '/ " . $size . " /s///g'");
      //file_put_contents("xxx.ksh", $didea);
        if ($didea != '') { return $didea; }
      }
      return shell_exec("find " . $folder . " -type f -name \"" . $pattern . "\" 2> /dev/null -exec wc -c {} + | egrep '^ " . $size . " ' | sed '/ " . $size . " /s///g'");
    }
    //$iti = new RecursiveDirectoryIterator($folder);
    //foreach (new RecursiveIteratorIterator($iti) as $file) {
    //foreach (glob($folder . $pattern) as $file) {
    //     if (strpos($file , $pattern) !== false && filesize($file) == $size) {
    //        return $file;
    //     }
    //}
    return '';
}

if (isset($_GET['filename']) && isset($_GET['filesize']) && !isset($_GET['filepath'])) {
  if (file_exists(str_replace('+',' ',urldecode($_GET['filename'])))) {
    if (filesize(str_replace('+',' ',urldecode($_GET['filename']))) == $_GET['filesize']) {
      $filepath=rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['filename']));
    }
  }
  if ($filepath == '') {
    $filepath = rsearch(DIRECTORY_SEPARATOR, str_replace('+',' ',urldecode($_GET['filename'])), $_GET['filesize']);
  }
  echo "<html><body onload=\"if (parent.document.getElementById('path').value == '') { parent.document.getElementById('path').value='" . explode(str_replace('+',' ',urldecode($_GET['filename'])), $filepath)[0] . "'; }\"></body></html>";
  exit;
} else if (isset($_GET['filename']) && isset($_GET['filesize']) && $_GET['filepath'] == '') {
  if (file_exists(str_replace('+',' ',urldecode($_GET['filename'])))) {
    if (filesize(str_replace('+',' ',urldecode($_GET['filename']))) == $_GET['filesize']) {
      $filepath=rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['filename']));
    }
  }
  if ($filepath == '') {
    $filepath = rsearch(DIRECTORY_SEPARATOR, str_replace('+',' ',urldecode($_GET['filename'])), $_GET['filesize']);
  }
  echo "<html><body onload=\"if (parent.document.getElementById('path').value == '') { parent.document.getElementById('path').value='" . explode(str_replace('+',' ',urldecode($_GET['filename'])), $filepath)[0] . "'; }\"></body></html>";
  exit;
} else if (isset($_GET['filename']) && isset($_GET['filesize']) && isset($_GET['filepath'])) {
  $anyextrac='';
  if (substr(str_replace('+',' ',urldecode($_GET['filepath'])), -1, 1) != DIRECTORY_SEPARATOR) {
    $anyextrac=DIRECTORY_SEPARATOR;
  }
  echo "<html><body onload=\"if (parent.document.getElementById('path').value == '') { parent.document.getElementById('path').value='" . str_replace('+',' ',urldecode($_GET['filepath'])) . $anyextac . "'; }\"></body></html>";
  exit;
}

$outp='ideas';
if (isset($_GET['outprefix'])) {
  $outp=str_replace('+',' ',urldecode($_GET['outprefix']));
  if (trim($outp) == "") { $outp='ideas'; }
} else if (isset($_POST['outprefix'])) {
  $outp=str_replace('+',' ',urldecode($_POST['outprefix']));
  if (trim($outp) == "") { $outp='ideas'; }
}

$bigp='';
if (PHP_OS == "Darwin") {
  $bigp='/usr/local/bin/';
}
if ($dohtml) {
if (isset($_GET['dohtml']) && isset($_GET['pdfbighp'])) {
  if (!is_dir(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['pdfbighp'])))) {
    mkdir(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['pdfbighp'])));
  }
  $pdfh='pdftohtml -c ' . $infile . ' ' . rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . DIRECTORY_SEPARATOR . "index 2> pdftohtml.bad ; ";
  $pdfbigh=$bigp . $pdfh;
} else if (isset($_POST['dohtml']) && isset($_POST['pdfbighp'])) {
  if (!is_dir(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_POST['pdfbighp'])))) {
    mkdir(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_POST['pdfbighp'])));
  }
  $pdfh='pdftohtml -c ' . $infile . ' ' . rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_POST['pdfbighp'])) . DIRECTORY_SEPARATOR  . "index 2> pdftohtml.bad ; ";
  $pdfbigh=$bigp . $pdfh;
}
}

if ($doxml) {
if (isset($_GET['doxml']) && isset($_GET['pdfbighp'])) {
  if (!is_dir(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['pdfbighp'])))) {
    mkdir(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['pdfbighp'])));
  }
  $pdfh.='pdftohtml -c -xml ' . $infile . ' ' . rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . DIRECTORY_SEPARATOR  .  $outp . " 2> pdftoxml.bad ;";
  $pdfbigh.=$bigp . 'pdftohtml -c -xml ' . $infile . ' ' . rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . DIRECTORY_SEPARATOR  .  $outp . " 2> pdftoxml.bad ;";
} else if (isset($_POST['doxml']) && isset($_POST['pdfbighp'])) {
  if (!is_dir(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_POST['pdfbighp'])))) {
    mkdir(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_POST['pdfbighp'])));
  }
  $pdfh.='pdftohtml -c -xml ' . $infile . ' ' . rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_POST['pdfbighp'])) . DIRECTORY_SEPARATOR  .  $outp . " 2> pdftoxml.bad ;";
  $pdfbigh.=$bigp . 'pdftohtml -c -xml ' . $infile . ' ' . rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_POST['pdfbighp'])) . DIRECTORY_SEPARATOR  .  $outp . " 2> pdftoxml.bad ;";
} 
}

$origoutp=$outp;

$hashbit="";
$olhashbit="";

    if ($outp != strtoupper($outp)) { 
    if ($doag && $dovideo) {
      $autoplay=' autoplay';
      $hashbit=" + '#" . strtoupper($outp) . ".mp4#" . strtoupper($outp) . ".gif'";
    } else if ($dovideo) {
      $autoplay=' autoplay';
      $hashbit=" + '#" . strtoupper($outp) . ".mp4'";
    } else if ($doag) {
      $hashbit=" + '#" . strtoupper($outp) . ".gif'";
    }
    if ($dohtml) {
    if ($hashbit == '') {
      $hashbit=" + '#" . strtoupper($outp) . ".html'";
    } else {
      $hashbit.=" + '#" . strtoupper($outp) . ".html'";
    }
    }
    if ($doxml) {
    if ($hashbit == '') {
      $hashbit=" + '#" . strtoupper($outp) . ".xml'";
    } else {
      $hashbit.=" + '#" . strtoupper($outp) . ".xml'";
    }
    }
   } else {
    $defdef=' ';
    }
    
 if (!$dopdf && $hashbit != '' && $outp != strtoupper($outp)) {
   $olhashbit='<iframe id=mysif style=display:none; src=./php_calls_pdfimages.php onload="delit(false,' . "''" . str_replace($outp, strtoupper($outp), $hashbit) . ');"></iframe>';
 } else if ($dopdf && $hashbit != '' && $outp != strtoupper($outp)) {
   $olhashbit='<iframe id=mysif style=display:none; src=./php_calls_pdfimages.php onload="delit(false,' . "'" . strtoupper(${outp}) . ".pdf'" . $hashbit . ');"></iframe>';
 } else if ($dopdf && $hashbit == '' && $outp != strtoupper($outp)) {
   $olhashbit='<iframe mysif style=display:none; src=./php_calls_pdfimages.php onload="delit(false,' . "'" . strtoupper(${outp}) . ".pdf'" . $hashbit . ');"></iframe>';
 }
 
 $outp=strtoupper($outp);

$proposedtable="<html>
<head>
<style>
 td { vertical-align: top; }
 .irandom { border:2px solid transparent; vertical-align: top; }
 span { background-color: #fafafa; }
 #thetable {  background-color:#f6f6f6; }
 #bothr { height: 8px; }
 #smode { z-index: 234; }
 .share { border: 2px solid transparent; }
</style>
<scr" . "ipt type=text/javascript>
   var outpaths=[], outnames=[];
   var bo='3px dashed orange';
   var boo=null;
   var ourwording='&wording=Pdfimages%20images%2E%20';
   var ajdone=false;
   var dmode='ltor';
   var lastpath='', lastfilename='';
   var gfirstparam=false, gsecondparam='', defem='" . $defdef . "', defs='" . $defdef . "', gblurb='';
   var zf='';

   function rmzipit(zwhat) {
    zf=zwhat;
    var zhr = new XMLHttpRequest();
    var zform=new FormData();
    zform.append('rmzip', zf);
    zhr.open('post', document.URL.split('?')[0].split('#')[0], true);
    zhr.send(zform);
   }

   function booit() {
     if (bo.indexOf(' orange') != -1) {
       bo=bo.replace(' orange', ' red');
       document.getElementById('mysbut').style.border=bo; //boo.style.border=bo;
     } else {
       bo=bo.replace(' red', ' orange');
       document.getElementById('mysbut').style.border=bo; //boo.style.border=bo;
     }
     setTimeout(booit, 3000);
   }
 
   function woit(ioo) {
     var wo=null;
     if (ioo.src.indexOf('data:') == 0) {
      wo=window.open('', '_blank');
      wo.document.write('<img title=\"' + ioo.title + '\" src=\"' + ioo.src + '\"></img>');
      wo.document.title=ioo.title;
     } else {
      window.open(ioo.src, '_blank');
     }
   }
   
   
  function appit(cbthis) {
    //alert(cbthis.getAttribute('data-append'));
    commandit(cbthis.getAttribute('data-append'));
    outpaths=[];
    outnames=[];
    document.getElementById('thewords').value=cbthis.getAttribute('data-append').split('" . DIRECTORY_SEPARATOR . "')[eval(-1 + cbthis.getAttribute('data-append').split('" . DIRECTORY_SEPARATOR . "').length)].replace(String.fromCharCode(34),'');
    document.getElementById('path').value=cbthis.getAttribute('data-append').split(String.fromCharCode(34))[5].split(document.getElementById('thewords').value)[0];
    cbthis.checked=false;
    cbthis.style.display='none';
    document.getElementById('sappend').innerHTML='';
  }

  function checkf() {
    var bcols=['#0000ff','#00ff00','#ff0000','#ffff00','#ff00ff','#00ffff','#777777','#000077','#007700','#770000','#777700','#770077','#007777'];
    var bids=['vemail', 'vsms', 'aemail', 'asms', 'pemail', 'psms', 'hemail', 'hsms', 'hemail', 'hsms'];
    if (document.getElementById('justputpdffilename')) {
    if (document.getElementById('justputpdffilename').innerHTML.toLowerCase().indexOf('.pdf') != -1) {
      document.getElementById('justputpdffilename').title=document.getElementById('justputpdffilename').innerHTML;
      document.getElementById('justputpdffilename').innerHTML='';
      if (document.getElementById('thewords').value.trim() == '' || document.getElementById('thewords').value == lastfilename) {
        document.getElementById('thewords').value=document.getElementById('justputpdffilename').title;
      if (document.getElementById('cbi') && document.getElementById('justputpdffilesize').innerHTML.trim() != document.getElementById('justputpdffilesize').innerHTML) {
        document.getElementById('cbi').style.height='252px';
      }
        lastfilename=document.getElementById('justputpdffilename').title;
        outnames.push(lastfilename);
      }
      if (document.getElementById('justputpdfpath').innerHTML == '' && document.getElementById('justputpdfpath').title == '') {
        if (document.getElementById('justputpdffilesize').innerHTML != '') {
          //alert('am going away to look for filename=' + lastfilename + ' of size ' + document.getElementById('justputpdffilesize').innerHTML.trim());
          document.getElementById('justputpdfpath').title=' ';
          //var xx=prompt(document.URL.split('?')[0].split('#')[0] + '?filepath=&filesize=' + document.getElementById('justputpdffilesize').innerHTML.trim() + '&filename=' + encodeURIComponent(lastfilename), document.URL.split('?')[0].split('#')[0] + '?filepath=&filesize=' + document.getElementById('justputpdffilesize').innerHTML.trim() + '&filename=' + encodeURIComponent(lastfilename));
          document.getElementById('path').style.cursor='progress';
          lastpath='';
          document.getElementById('gifif').src='./php_calls_pdfimages.php?filepath=&filesize=' + document.getElementById('justputpdffilesize').innerHTML.trim() + '&filename=' + encodeURIComponent(lastfilename);
        }
      }
    } else if (document.getElementById('justputpdffilename').innerHTML != '') {
      document.getElementById('justputpdffilename').innerHTML='';
      document.getElementById('justputpdffilesize').innerHTML='';
    }
    if (document.getElementById('justputpdfpath').innerHTML != '') {
      document.getElementById('justputpdfpath').title=document.getElementById('justputpdfpath').innerHTML;
      document.getElementById('justputpdfpath').innerHTML='';
      if (document.getElementById('justputpdfpath').title.indexOf('/') != -1) {
        if (document.getElementById('justputpdfpath').title.slice(-1) != '/') {
          document.getElementById('justputpdfpath').title+='/';
        }
      } else {
        if (document.getElementById('justputpdfpath').title.slice(-1) != String.fromCharCode(92)) {
          document.getElementById('justputpdfpath').title+=String.fromCharCode(92);
        }
      }
      if (document.getElementById('path').value.trim() == '' || document.getElementById('path').value == lastpath) {
        document.getElementById('path').value=document.getElementById('justputpdfpath').title;
        lastpath=document.getElementById('justputpdfpath').title;
        outpaths.push(lastpath);
        if (eval('' + outnames.length) > 1 && eval('' + outpaths.length) > 1) {
        //alert('okay');
          document.getElementById('sappend').innerHTML=' ... versus <input data-append=' + String.fromCharCode(39) + 'pdfunite \"' +  outpaths[eval(-2 + outnames.length)] + outnames[eval(-2 + outnames.length)] + '\" \"' +  outpaths[eval(-1 + outnames.length)] + outnames[eval(-1 + outnames.length)] + '\" \"' + '" . sys_get_temp_dir() . DIRECTORY_SEPARATOR . "' + outnames[eval(-2 + outnames.length)].split('.')[0] + outnames[eval(-1 + outnames.length)].split('.')[0] + '.pdf\"' + String.fromCharCode(39) + ' style=display:inline-block; type=checkbox onchange=appit(this);>\"' + '" . sys_get_temp_dir() . DIRECTORY_SEPARATOR . "' + outnames[eval(-2 + outnames.length)].split('.')[0] + outnames[eval(-1 + outnames.length)].split('.')[0] + '.pdf\"</input>';
        }
      } else if (document.getElementById('path').value.trim() != '') {
        //alert('oops');
      }
    }
    if (document.getElementById('path').value != '') {
      if (lastpath == '') {
        //alert('okaY');
        lastpath='';
        lastpath=document.getElementById('path').value;
        outpaths.push(lastpath);
        if (eval('' + outnames.length) > 1 && eval('' + outpaths.length) > 1) {
        //alert('okay');
          document.getElementById('sappend').innerHTML=' ... versus <input data-append=' + String.fromCharCode(39) + 'pdfunite \"' +  outpaths[eval(-2 + outnames.length)] + outnames[eval(-2 + outnames.length)] + '\" \"' +  outpaths[eval(-1 + outnames.length)] + outnames[eval(-1 + outnames.length)] + '\" \"' + '" . sys_get_temp_dir() . DIRECTORY_SEPARATOR . "' + outnames[eval(-2 + outnames.length)].split('.')[0] + outnames[eval(-1 + outnames.length)].split('.')[0] + '.pdf\"' + String.fromCharCode(39) + ' style=display:inline-block; type=checkbox onchange=appit(this);>\"' + '" . sys_get_temp_dir() . DIRECTORY_SEPARATOR . "' + outnames[eval(-2 + outnames.length)].split('.')[0] + outnames[eval(-1 + outnames.length)].split('.')[0] + '.pdf\"</input>';
        }
        lastpath=' ';
      }
      document.getElementById('path').style.cursor='pointer';
    }
    }
    for (var ii=0; ii<bids.length; ii++) {
      if (document.getElementById(bids[ii])) {
        if (defem.trim() != '' || defs.trim() != '' || defem != '' || defs != '') {
        document.getElementById(bids[ii]).style.border='2px solid transparent';
        } else if (defem != '' || defs != '') {
        document.getElementById(bids[ii]).style.border='2px dashed ' + bcols[Math.floor(Math.random() * bcols.length)];
        } else {
        document.getElementById(bids[ii]).style.border='2px dotted ' + bcols[Math.floor(Math.random() * bcols.length)];
        }
      }
    }
  }


function iifopen(iois) {
  if (iois != null) {
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto.document) { aconto = aconto.document; }
    if (aconto != null) {
    //alert(1);
      if (aconto.getElementById('distyle')) {
        aconto.getElementById('distyle').innerHTML+='<style> input[type=file]::file-selector-button { background-color: pink; } </style>';
        aconto.getElementById('files').accept='.pdf';
        aconto.getElementById('files').multiple=false;
        aconto.getElementById('files').style.border='5px solid yellow';
        arect=aconto.getElementById('files').getBoundingClientRect();
        //alert(2);
        //aconto.getElementById('files').click();
      }
    }
  }
}
  

   function toggle() {
     document.getElementById('myh4').scrollIntoView(); // location.href='#myh4';
     if (dmode == 'ltor') {
       dmode='ttob';
       document.getElementById('smode').innerHTML='&#11015;';
       document.getElementById('mydflex').style.display='none';
       document.getElementById('mytable').style.display='none';
       document.getElementById('mytabletwo').style.display='table';
     } else if (dmode == 'ttob') {
       dmode='fill';
       document.getElementById('smode').innerHTML='&#10145;';
       document.getElementById('mydflex').style.display='none';
       document.getElementById('mytabletwo').style.display='none';
       document.getElementById('mytable').style.display='table';
     } else {
       dmode='ltor';
       document.getElementById('smode').innerHTML='&#8600;';
       document.getElementById('mytable').style.display='none';
       document.getElementById('mytabletwo').style.display='none';
       document.getElementById('mydflex').style.display='block';
     }     
   }
   
function stayex() {
   if (defem == '' && defs == '') { defem=' '; 
   if (gfirstparam) { delit(gfirstparam, gsecondparam); }
   }
   return true;
}

function emailit(inais) {
   event.stopPropagation();
   if (gfirstparam) { delit(gfirstparam, gsecondparam); }
   var ext='.mp4';
   if (defem == '') { defem=' '; }
   var ouroutp='" . strtoupper($outp) . "';
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'h') {  ext='.html';  ouroutp='" . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "' + '" . DIRECTORY_SEPARATOR . "' + 'index'; }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'x') {  ext='.xml';  ouroutp='" . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "' + '" . DIRECTORY_SEPARATOR . "' + '" . $outp . "';   }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'a') {  ext='.gif';  }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'p') {  ext='.pdf ( or perhaps you want original PDF at " . $infile . " )';  }
   //var em=prompt('Please enter email address to send to for an email message to which you might attach " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . strtoupper($outp) . "' + ext, '');
   var em=prompt('Please enter email address to send to for an email message to which you might attach " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "' + ouroutp + ext + ' (or other " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . strtoupper($outp) . "*.* prefixing' + ' image or other media files, and note that right clicking images below is another sharing possibility)' + gblurb, defem.trim());
   if (em == null) { em=''; }
   if (em.indexOf('@') != -1) {
     if (em.trim() != em && gblurb.trim() != '') {
       gblurb=' ';
       setTimeout(tryagain, 120000);
     }     
     defem=em.trim();
     document.getElementById('dimap').innerHTML=\"<a style=display:none; id=theaemail target=_blank href='mailto:\" + em + \"?subject=Media%20Share'>Email</a>\";
     document.getElementById('theaemail').click();
   } else if (em.trim() == '' && em != '') {
     if (em.trim() != em && gblurb.trim() != '') {
       gblurb=' ';
       setTimeout(tryagain, 120000);
     }     
   }
   return false;
}

function smsit(inais) {
   event.stopPropagation();
   if (gfirstparam) { delit(gfirstparam, gsecondparam); }
   var ext='.mp4';
   if (defs == '') { defs=' '; }
    var ouroutp='" . strtoupper($outp) . "';
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'h') {  ext='.html';  ouroutp='" . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "' + '" . DIRECTORY_SEPARATOR . "' + 'index'; }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'x') {  ext='.xml';  ouroutp='" . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "' + '" . DIRECTORY_SEPARATOR . "' + '" . $outp . "';   }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'a') {  ext='.gif';  }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'p') {  ext='.pdf ( or perhaps you want original PDF at " . $infile . " )';  }
   var em=prompt('Please enter SMS number to send to for an SMS message to which you might attach " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "' + ouroutp + ext + ' (or other " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . strtoupper($outp) . "*.* prefixing' + ' image or other media files, and note that right clicking images below is another sharing possibility)' + gblurb, defs.trim());
   if (em == null) { em=''; }
   if (em.trim() != '') { 
     if (em.trim() != em && gblurb.trim() != '') {
       gblurb=' ';
       setTimeout(tryagain, 120000);
     }     
     if (em.trim() != '') {
     defs=em.trim();    
     document.getElementById('dimap').innerHTML=\"<a style=display:none; id=theasms target=_blank href='sms:\" + em + \"'>SMS</a>\";
     document.getElementById('theasms').click();
     }
   }
   return false;
}

function oldsmsit(inais) {
   event.stopPropagation();
   if (gfirstparam) { delit(gfirstparam, gsecondparam); }
   var ext='.mp4';
   if (defs == '') { defs=' '; }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'a') {  ext='.gif';  }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'p') {  ext='.pdf ( or perhaps you want original PDF at " . $infile . " )';  }
   var em=prompt('Please enter SMS number to send to for an SMS message to which you might attach " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . strtoupper($outp) . "' + ext + ' (or other " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . strtoupper($outp) . "*.* prefixing' + ' image or other media files, and note that right clicking images below is another sharing possibility)' + gblurb, defs.trim());
   if (em == null) { em=''; }
   if (em.trim() != '') { 
     if (em.trim() != em && gblurb.trim() != '') {
       gblurb=' ';
       setTimeout(tryagain, 120000);
     }     
     if (em.trim() != '') {
     defs=em.trim();    
     document.getElementById('dimap').innerHTML=\"<a style=display:none; id=theasms target=_blank href='sms:\" + em + \"'>SMS</a>\";
     document.getElementById('theasms').click();
     }
   }
   return false;
}

function tryagain() {
  ajdone=false;
  delit(false, gsecondparam);
}

function commandit(whatc) {
    var zhr = new XMLHttpRequest();
    var zform=new FormData();
    zform.append('pdfunitec', whatc);
    zhr.open('post', document.URL.split('?')[0].split('#')[0], true);
    zhr.send(zform);
}

function delit(istouch, ioissrc) {
  var doit=false;
  var thingos=ioissrc.split('#');
  var zhr = new XMLHttpRequest();
  var zform=new FormData();
  var dgebih='<iframe name=ifdf id=ifdf style=display:none; src=./php_calls_pdfimages.php></iframe><form target=ifdf style=display:none; method=POST action=./php_calls_pdfimages.php><input type=submit id=divformb value=Submit></input></form>';
  if (!istouch && gblurb == '') {
    gfirstparam=true;
    gsecondparam=ioissrc;
    gblurb='.  Add spaces to say that it is okay, that in two minutes, will tidy up media files, as first requested.';
  }
  if (thingos[0].length > 0) {
    doit=true;
    zform.append('delp', ioissrc.split('#')[0]);
    dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=delp id=delp value=\"' + ioissrc.split('#')[0] + '\"></input><input type=submit');
  }
  for (var ijk=1; ijk<thingos.length; ijk++) {
  if (thingos.length > 1) {
    if (thingos[ijk].indexOf('.mp4') != -1) {
    doit=true;
  zform.append('delv', thingos[ijk]);
    dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=delv id=delv value=\"' + thingos[ijk] + '\"></input><input type=submit');
    } else if (thingos[ijk].indexOf('.gif') != -1) {
    doit=true;
  zform.append('dela', thingos[ijk]);
    dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=dela id=dela value=\"' + thingos[ijk] + '\"></input><input type=submit');
    } else if (thingos[ijk].indexOf('.html') != -1) {
    doit=true;
  zform.append('delh', thingos[ijk]);
    dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=delh id=delh value=\"' + thingos[ijk] + '\"></input><input type=submit');
    } else if (thingos[ijk].indexOf('.xml') != -1) {
    doit=true;
  zform.append('delx', thingos[ijk]);
    dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=delx id=delx value=\"' + thingos[ijk] + '\"></input><input type=submit');
    }
  }
  }
  if (istouch) {
    zform.append('touch', 'y');
    console.log('YES ' + doit + ' ' + gsecondparam + ' and gblurb=' + gblurb);
  }
  if ('" . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "' != '') {
  doit=true;
  zform.append('pdfbighp', '" . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "');
  dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=dela id=dela value=\"' + '" . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "' + '\"></input><input type=submit');
  }
  if (doit && (!ajdone || istouch)) {
  if (!istouch) {
  document.getElementById('dpf').innerHTML=dgebih;
  document.getElementById('divformb').click();
  //alert('0:' + dgebih);
  } else {
  zhr.open('post', document.URL.split('?')[0].split('#')[0], true);
  zhr.send(zform);
  }
  }
  ajdone=true;
}
   

  setInterval(checkf, 1000);
</scr" . "ipt>
</head>
<body onload=\" document.getElementById('sw').value='' + screen.width;\">
<h1 style=margin-left:5px; id=myh1>Extract the Images Within a PDF <span style=cursor:pointer; onclick=\"location.href='#bothr';\">File" . $fextra . "</span> via <span title='Install pdfimages if not installed before via double click' style=cursor:pointer; ondblclick=\"window.open('./php_calls_pdfimages.php?install=pdfimages','_blank','top=200,left=200,width=700,height=400');\">Pdfimages</span> then <span title='Install ffmpeg if not installed before via double click' style=cursor:pointer; ondblclick=\"window.open('./php_calls_pdfimages.php?install=ffmpeg','_blank','top=200,left=200,width=700,height=400');\">Ffmpeg</span> and/or <span title='Install ImageMagick if not installed before via double click' style=cursor:pointer; ondblclick=\"window.open('./php_calls_pdfimages.php?install=imagemagick','_blank','top=200,left=200,width=700,height=400');\">ImageMagick</span></h1>
<h3 style=margin-left:5px; id=myh3x>RJM Programming <span id=smode style=cursor:pointer; onclick=toggle(); title='Click to toggle among left to right and top to bottom and width filling modes of image display'>&#10145;</span> April, 2023</h3>
<br><br>
<div id=\"dinstall\"></div>
<h4 id=myh4 onclick=\"document.getElementById('myh1').scrollIntoView();\" style=cursor:pointer; title='Back to top'></h4><br>
<table id=\"mytable\"><tbody id=mytbody><tr id=mytr></tr></tbody></table>
<table id=mytabletwo style=display:none;><tbody id=mythead><tr id=mytrtwo></TR></thead></table>
<div id=mydflex class='flexContainer' style=display:none;float:top;width:" . $vsw . ";></DIV>
<br><br>
<hr id=bothr title='Click to go back to top' onclick=\"location.href='#myh1';\"></hr>" . $olhashbit . "
<iframe src=./php_calls_pdfimages.php frameborder=0 style='width:100%;height:1200px;'></iframe>
<!--table id='thetable'><tbody><tr><td><iframe scrolling='no' onload='iifopen(this);' id='cbi' frameborder='0' style='width:173px;height:228px;margin-top:-184px;' src='/HTMLCSS/client_browsing.htm?d=312160562686&wording=Pdfimages%20images%2E%20'></iframe></td><td id='lstd'></td></tr></tbody></table>
<p id='myp'> ... or ...</p>
<hr id='hr1'></hr>
<br><br><form style=margin-left:5px; method=POST action=./php_calls_pdfimages.php>
<input title='Path' name='inpath' style='display:inline-block;width:50%;' type='text' id='path' value='' placeholder='Optional input path'><br><br>
<input type='text' data-onblur=\"if (document.URL.toLowerCase().indexOf('rjmprogramming.com.au') != -1) { this.value=''; } else { assessit(this.value); }\" style='width:45%;display:inline-block;' title='Use + (perhaps just by itself) rather than comma to define a list that results in one output file for concatenated or merged media.  Use - to flatten out an Animated GIF or video or PDF.' placeholder='Input PDF file' id='thewords' name='convertthis' value=''><span id=sappend></span><br><br>
<input type=hidden name=sw id=sw value=0></input><input type=hidden name=\"delp\" id=\"delp\" value=\"\"></input><input title='Output prefix' name='outprefix' style='display:inline-block;width:50%;' type='text' id='outpath' value='' placeholder='Optional output *.jpg file prefix [ideas] ... fully capitalize to retain'>&nbsp;<input style=display:inline-block; type=checkbox checked name=dovideo id=dovideo>Video</input>&nbsp;<input style=display:inline-block; type=checkbox checked name=doag id=doag>Animated GIF</input>&nbsp;<input type=checkbox style=display:inline-block; name=dopdf id=dopdf>Image PDF</input>&nbsp;<input type=checkbox style=display:inline-block; name=dohtml id=dohtml>HTML</input>&nbsp;<input type=checkbox style=display:inline-block; name=doxml id=doxml>XML</input><input type=hidden name=pdfbighp id=pdfbighp value=pdftohtml_" . rand(123, 15678956) . "></input><br><br>
<input onclick=\"this.style.cursor='progress'; this.style.border='3px dashed orange'; boo=this; setTimeout(booit, 3000);\" id=mysbut type=submit value='Extract Images (and maybe Create Video and/or Animated GIF and/or Image PDF and/or HTML and/or XML) From ...' style='background-color:yellow;'></input>
</form>
<div id='dpf' style='display:none;'></div>
<div id='dimap'></div>
<div title=' ' id=justputpdfpath style=display:none;></div>
<div title='' id=justputpdffilename style=display:none;></div>
<div title='' id=justputpdffilesize style=display:none;></div>
<iframe style='display:none;' id='gifif' name='gifif' src='//www.rjmprogramming.com.au/About_Us.html'></iframe></div-->
</body>
</html>";

if (isset($_GET['convertthis'])) {
  $infile='"' . $pathp . str_replace('+',' ',urldecode($_GET['convertthis'])) . '"';
  //$fextra='<font color="black" size=1>&nbsp;' . basename(str_replace('"','',$infile)) . '</font>';
  $fextra='<font color="black" size="1">&nbsp;<a onclick="document.getElementById(' . "'mysif'" . ').src=document.URL.split(String.fromCharCode(63))[0].split(String.fromCharCode(35))[0] + ' . "'" . '?nopdfurl=y' . "'" . ';" target="_blank" title="Original PDF is ' . str_replace('"',"'",$infile) . '" href="' . $pdfprotocol . str_replace('+','%20',oururlencode(str_replace('"','',$infile))) . '">' . basename(str_replace('"','',$infile)) . '</a></font>';
//file_put_contents('xa3.xa3', $fextra);
} else if (isset($_POST['convertthis'])) {
  $infile='"' . $pathp . str_replace('+',' ',urldecode($_POST['convertthis'])) . '"';
  //$fextra='<font size=1>&nbsp;' . basename(str_replace('"','',$infile)) . '</font>';
  $fextra='<font color="black" size="1">&nbsp;<a onclick="document.getElementById(' . "'mysif'" . ').src=document.URL.split(String.fromCharCode(63))[0].split(String.fromCharCode(35))[0] + ' . "'" . '?nopdfurl=y' . "'" . ';" target="_blank" title="Original PDF is ' . str_replace('"',"'",$infile) . '" href="' . $pdfprotocol . str_replace('+','%20',oururlencode(str_replace('"','',$infile))) . '">' . basename(str_replace('"','',$infile)) . '</a></font>';
//file_put_contents('xa4.xa4', $fextra);
} else if (strpos(('' . $_SERVER['SERVER_NAME']), "localhost") === false) {
  echo "<html>
<body onload=\" if (('' + window.navigator.platform).toLowerCase().indexOf('mac') == 0) { window.open('HTTP://localhost:8888/php_calls_pdfimages.php','_blank','top=150,left=0,width=' + screen.width + ',height=600'); } else {  window.open('HTTP://localhost/php_calls_pdfimages.php','_blank','top=150,left=0,width=' + screen.width + ',height=600');  }\">" . str_replace(explode('>', explode('</body>', explode("<body", str_replace($rest, $restto, $proposedtable))[1])[0])[0] . '>', '', explode('</body>', explode("<body", str_replace($rest, $restto, $proposedtable))[1])[0]) . "

</body>
</html>";


echo str_replace($rest, $restto, $proposedtable);

  //exit;
} else {
  echo "<html>
<head>
<style>

 #smode { z-index: 234; }
 span { background-color: #fafafa; }
 select { width: 180px; }
 h3 { vertical-align: top; }
 #bothr { height: 8px; }
 .share { border: 2px solid transparent; }
 
 #thetable {  background-color:#f6f6f6; }
 .irandom { border:2px solid transparent; vertical-align: top; }

 .custom-alert {
  display: inline-block;
  /* visibility: visible; */
  background-color: rgba(102,102,102,0.8);
  color: #fff;
  text-align: center;
  margin: 5% auto;
  padding: 12px 28px;
  opacity: 0.9;
  z-index: 200;
  -webkit-animation: glow 1s linear infinite alternate;
  -moz-animation: glow 1s linear infinite alternate;
  animation: glow 1s linear infinite alternate;
 }

 .custom-prompt {
  display: inline-block;
  /* visibility: visible; */
  background-color: rgba(202,202,202,0.8);
  color: #fff;
  text-align: center;
  margin: 5% auto;
  padding: 12px 28px;
  opacity: 0.9;
  z-index: 200;
  -webkit-animation: wglow 1s linear infinite alternate;
  -moz-animation: wglow 1s linear infinite alternate;
  animation: wglow 1s linear infinite alternate;
 }
 
 body { 
   margin: 0 0 0 0; 
   padding: 0 0 0 0; 
 }
 
 .dblob {
   text-align: center;
   vertical-align: middle;
 }

 /* Thanks to https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_glowing_text */

 @-webkit-keyframes glow {
  from {
    box-shadow: 0 0 3px #fff, 0 0 5px #fff, 0 0 37px #e60073, 0 0 9px #e60073, 0 0 11px #e60073, 0 0 13px #e60073, 0 0 15px #e60073;
  }

  to {
    box-shadow: 0 0 24px #fff, 0 0 6px #ff4da6, 0 0 8px #ff4da6, 0 0 10px #ff4da6, 0 0 12px #ff4da6, 0 0 14px #ff4da6, 0 0 16px #ff4da6;
  }
 }


 @-webkit-keyframes wglow {
  from {
    box-shadow: 0 0 3px #fff, 0 0 5px #fff, 0 0 37px #7300e6, 0 0 9px #7300e6, 0 0 11px #7300e6, 0 0 13px #7300e6, 0 0 15px #7300e6;
  }

  to {
    box-shadow: 0 0 24px #fff, 0 0 6px #ff4da6, 0 0 8px #a64dff, 0 0 10px #a64dff, 0 0 12px #a64dff, 0 0 14px #a64dff, 0 0 16px #a64dff;
  }
 }

</style>
<scr" . "ipt type=text/javascript>
  var ourwording='&wording=Pdfimages%20images%2E%20';
  var ajdone=false;
  var bo='3px dashed orange';
  var boo=null;
  var lastpath='', lastfilename='';
  var gfirstparam=false, gsecondparam='', defem='" . $defdef . "', defs='" . $defdef . "', gblurb='';
  var outnames=[], outpaths=[];
  var zf='';

   function rmzipit(zwhat) {
    zf=zwhat;
    var zhr = new XMLHttpRequest();
    var zform=new FormData();
    zform.append('rmzip', zf);
    zhr.open('post', document.URL.split('?')[0].split('#')[0], true);
    zhr.send(zform);
   }

   function booit() {
     if (bo.indexOf(' orange') != -1) {
       bo=bo.replace(' orange', ' red');
       document.getElementById('mysbut').style.border=bo; //boo.style.border=bo;
     } else {
       bo=bo.replace(' red', ' orange');
       document.getElementById('mysbut').style.border=bo; //boo.style.border=bo;
     }
     setTimeout(booit, 3000);
   }
   
  function appit(cbthis) {
    //alert(cbthis.getAttribute('data-append'));
    commandit(cbthis.getAttribute('data-append'));
    outpaths=[];
    outnames=[];
    document.getElementById('thewords').value=cbthis.getAttribute('data-append').split('" . DIRECTORY_SEPARATOR . "')[eval(-1 + cbthis.getAttribute('data-append').split('" . DIRECTORY_SEPARATOR . "').length)].replace(String.fromCharCode(34),'');
    document.getElementById('path').value=cbthis.getAttribute('data-append').split(String.fromCharCode(34))[5].split(document.getElementById('thewords').value)[0];
    cbthis.checked=false;
    cbthis.style.display='none';
    document.getElementById('sappend').innerHTML='';
  }

  function checkf() {
    var bcols=['#0000ff','#00ff00','#ff0000','#ffff00','#ff00ff','#00ffff','#777777','#000077','#007700','#770000','#777700','#770077','#007777'];
    var bids=['vemail', 'vsms', 'aemail', 'asms', 'pemail', 'psms', 'hemail', 'hsms', 'hemail', 'hsms'];
    if (document.getElementById('justputpdffilename')) {
    if (document.getElementById('justputpdffilename').innerHTML.toLowerCase().indexOf('.pdf') != -1) {
      document.getElementById('justputpdffilename').title=document.getElementById('justputpdffilename').innerHTML;
      document.getElementById('justputpdffilename').innerHTML='';
      if (document.getElementById('thewords').value.trim() == '' || document.getElementById('thewords').value == lastfilename) {
        document.getElementById('thewords').value=document.getElementById('justputpdffilename').title;
      if (document.getElementById('cbi') && document.getElementById('justputpdffilesize').innerHTML.trim() != document.getElementById('justputpdffilesize').innerHTML) {
        document.getElementById('cbi').style.height='252px';
      }
        lastfilename=document.getElementById('justputpdffilename').title;
        outnames.push(lastfilename);
      }
      if (document.getElementById('justputpdfpath').innerHTML == '' && document.getElementById('justputpdfpath').title == '') {
        if (document.getElementById('justputpdffilesize').innerHTML != '') {
          //alert('am going away to look for filename=' + lastfilename + ' of size ' + document.getElementById('justputpdffilesize').innerHTML.trim());
          document.getElementById('justputpdfpath').title=' ';
          //var xx=prompt(document.URL.split('?')[0].split('#')[0] + '?filepath=&filesize=' + document.getElementById('justputpdffilesize').innerHTML.trim() + '&filename=' + encodeURIComponent(lastfilename), document.URL.split('?')[0].split('#')[0] + '?filepath=&filesize=' + document.getElementById('justputpdffilesize').innerHTML.trim() + '&filename=' + encodeURIComponent(lastfilename));
          document.getElementById('path').style.cursor='progress';
          lastpath='';
          document.getElementById('gifif').src='./php_calls_pdfimages.php?filepath=&filesize=' + document.getElementById('justputpdffilesize').innerHTML.trim() + '&filename=' + encodeURIComponent(lastfilename);
        }
      }
    } else if (document.getElementById('justputpdffilename').innerHTML != '') {
      document.getElementById('justputpdffilename').innerHTML='';
      document.getElementById('justputpdffilesize').innerHTML='';
    }
    if (document.getElementById('justputpdfpath').innerHTML != '') {
      document.getElementById('justputpdfpath').title=document.getElementById('justputpdfpath').innerHTML;
      document.getElementById('justputpdfpath').innerHTML='';
      if (document.getElementById('justputpdfpath').title.indexOf('/') != -1) {
        if (document.getElementById('justputpdfpath').title.slice(-1) != '/') {
          document.getElementById('justputpdfpath').title+='/';
        }
      } else {
        if (document.getElementById('justputpdfpath').title.slice(-1) != String.fromCharCode(92)) {
          document.getElementById('justputpdfpath').title+=String.fromCharCode(92);
        }
      }
      if (document.getElementById('path').value.trim() == '' || document.getElementById('path').value == lastpath) {
        document.getElementById('path').value=document.getElementById('justputpdfpath').title;
        lastpath=document.getElementById('justputpdfpath').title;
        outpaths.push(lastpath);
        if (eval('' + outnames.length) > 1 && eval('' + outpaths.length) > 1) {
        //alert('Okay');
          document.getElementById('sappend').innerHTML=' ... versus <input data-append=' + String.fromCharCode(39) + 'pdfunite \"' +  outpaths[eval(-2 + outnames.length)] + outnames[eval(-2 + outnames.length)] + '\" \"' +  outpaths[eval(-1 + outnames.length)] + outnames[eval(-1 + outnames.length)] + '\" \"' + '" . sys_get_temp_dir() . DIRECTORY_SEPARATOR . "' + outnames[eval(-2 + outnames.length)].split('.')[0] + outnames[eval(-1 + outnames.length)].split('.')[0] + '.pdf\"' + String.fromCharCode(39) + ' style=display:inline-block; type=checkbox onchange=appit(this);>\"' + '" . sys_get_temp_dir() . DIRECTORY_SEPARATOR . "' + outnames[eval(-2 + outnames.length)].split('.')[0] + outnames[eval(-1 + outnames.length)].split('.')[0] + '.pdf\"</input>';
        }
      } else if (document.getElementById('path').value.trim() != '') {
        //alert('Oops');
      }
    }
    if (document.getElementById('path').value != '') {
      if (lastpath == '') {
        //alert('OkaY');
        lastpath='';
        lastpath=document.getElementById('path').value;
        outpaths.push(lastpath);
        if (eval('' + outnames.length) > 1 && eval('' + outpaths.length) > 1) {
        //alert('okay');
          document.getElementById('sappend').innerHTML=' ... versus <input data-append=' + String.fromCharCode(39) + 'pdfunite \"' +  outpaths[eval(-2 + outnames.length)] + outnames[eval(-2 + outnames.length)] + '\" \"' +  outpaths[eval(-1 + outnames.length)] + outnames[eval(-1 + outnames.length)] + '\" \"' + '" . sys_get_temp_dir() . DIRECTORY_SEPARATOR . "' + outnames[eval(-2 + outnames.length)].split('.')[0] + outnames[eval(-1 + outnames.length)].split('.')[0] + '.pdf\"' + String.fromCharCode(39) + ' style=display:inline-block; type=checkbox onchange=appit(this);>\"' + '" . sys_get_temp_dir() . DIRECTORY_SEPARATOR . "' + outnames[eval(-2 + outnames.length)].split('.')[0] + outnames[eval(-1 + outnames.length)].split('.')[0] + '.pdf\"</input>';
        }
        lastpath=' ';
      }
      document.getElementById('path').style.cursor='pointer';
    }
    }
    for (var ii=0; ii<bids.length; ii++) {
      if (document.getElementById(bids[ii])) {
        if (defem.trim() != '' || defs.trim() != '' || defem != '' || defs != '') {
        document.getElementById(bids[ii]).style.border='2px solid transparent';
        } else if (defem != '' || defs != '') {
        document.getElementById(bids[ii]).style.border='2px dashed ' + bcols[Math.floor(Math.random() * bcols.length)];
        } else {
        document.getElementById(bids[ii]).style.border='2px dotted ' + bcols[Math.floor(Math.random() * bcols.length)];
        }
      }
    }
  }


function iifopen(iois) {
  if (iois != null) {
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto.document) { aconto = aconto.document; }
    if (aconto != null) {
    //alert(1);
      if (aconto.getElementById('distyle')) {
        aconto.getElementById('distyle').innerHTML+='<style> input[type=file]::file-selector-button { background-color: pink; } </style>';
        aconto.getElementById('files').accept='.pdf';
        aconto.getElementById('files').multiple=false;
        aconto.getElementById('files').style.border='5px solid yellow';
        arect=aconto.getElementById('files').getBoundingClientRect();
        //alert(2);
        //aconto.getElementById('files').click();
      }
    }
  }
}

function stayex() {
   if (defem == '' && defs == '') { defem=' '; 
   if (gfirstparam) { delit(gfirstparam, gsecondparam); }
   }
   return true;
}

function outemailit(inais) {
   event.stopPropagation();
   if (gfirstparam) { delit(gfirstparam, gsecondparam); }
   var ext='.mp4';
   if (defem == '') { defem=' '; }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'a') {  ext='.gif';  }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'p') {  ext='.pdf ( or perhaps you want original PDF at " . $infile . " )';  }
   //var em=prompt('Please enter email address to send to for an email message to which you might attach " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . strtoupper($outp) . "' + ext, '');
   var em=prompt('Please enter email address to send to for an email message to which you might attach " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . strtoupper($outp) . "' + ext + ' (or other " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . strtoupper($outp) . "*.* prefixing' + ' image or other media files, and note that right clicking images below is another sharing possibility)' + gblurb, defem.trim());
   if (em == null) { em=''; }
   if (em.indexOf('@') != -1) {
     if (em.trim() != em && gblurb.trim() != '') {
       gblurb=' ';
       setTimeout(tryagain, 120000);
     }     
     defem=em.trim();
     document.getElementById('dimap').innerHTML=\"<a style=display:none; id=theaemail target=_blank href='mailto:\" + em + \"?subject=Media%20Share'>Email</a>\";
     document.getElementById('theaemail').click();
   } else if (em.trim() == '' && em != '') {
     if (em.trim() != em && gblurb.trim() != '') {
       gblurb=' ';
       setTimeout(tryagain, 120000);
     }     
   }
   return false;
}

function emailit(inais) {
   event.stopPropagation();
   if (gfirstparam) { delit(gfirstparam, gsecondparam); }
   var ext='.mp4';
   if (defem == '') { defem=' '; }
   var ouroutp='" . strtoupper($outp) . "';
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'h') {  ext='.html';  ouroutp='" . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "' + '" . DIRECTORY_SEPARATOR . "' + 'index'; }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'x') {  ext='.xml';  ouroutp='" . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "' + '" . DIRECTORY_SEPARATOR . "' + '" . $outp . "';   }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'a') {  ext='.gif';  }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'p') {  ext='.pdf ( or perhaps you want original PDF at " . $infile . " )';  }
   //var em=prompt('Please enter email address to send to for an email message to which you might attach " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . strtoupper($outp) . "' + ext, '');
   var em=prompt('Please enter email address to send to for an email message to which you might attach " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "' + ouroutp + ext + ' (or other " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . strtoupper($outp) . "*.* prefixing' + ' image or other media files, and note that right clicking images below is another sharing possibility)' + gblurb, defem.trim());
   if (em == null) { em=''; }
   if (em.indexOf('@') != -1) {
     if (em.trim() != em && gblurb.trim() != '') {
       gblurb=' ';
       setTimeout(tryagain, 120000);
     }     
     defem=em.trim();
     document.getElementById('dimap').innerHTML=\"<a style=display:none; id=theaemail target=_blank href='mailto:\" + em + \"?subject=Media%20Share'>Email</a>\";
     document.getElementById('theaemail').click();
   } else if (em.trim() == '' && em != '') {
     if (em.trim() != em && gblurb.trim() != '') {
       gblurb=' ';
       setTimeout(tryagain, 120000);
     }     
   }
   return false;
}


function smsit(inais) {
   event.stopPropagation();
   if (gfirstparam) { delit(gfirstparam, gsecondparam); }
   var ext='.mp4';
   if (defs == '') { defs=' '; }
    var ouroutp='" . strtoupper($outp) . "';
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'h') {  ext='.html';  ouroutp='" . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "' + '" . DIRECTORY_SEPARATOR . "' + 'index'; }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'x') {  ext='.xml';  ouroutp='" . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "' + '" . DIRECTORY_SEPARATOR . "' + '" . $outp . "';   }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'a') {  ext='.gif';  }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'p') {  ext='.pdf ( or perhaps you want original PDF at " . $infile . " )';  }
   var em=prompt('Please enter SMS number to send to for an SMS message to which you might attach " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "' + ouroutp + ext + ' (or other " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . strtoupper($outp) . "*.* prefixing' + ' image or other media files, and note that right clicking images below is another sharing possibility)' + gblurb, defs.trim());
   if (em == null) { em=''; }
   if (em.trim() != '') { 
     if (em.trim() != em && gblurb.trim() != '') {
       gblurb=' ';
       setTimeout(tryagain, 120000);
     }     
     if (em.trim() != '') {
     defs=em.trim();    
     document.getElementById('dimap').innerHTML=\"<a style=display:none; id=theasms target=_blank href='sms:\" + em + \"'>SMS</a>\";
     document.getElementById('theasms').click();
     }
   }
   return false;
}


function oldsmsit(inais) {
   event.stopPropagation();
   if (gfirstparam) { delit(gfirstparam, gsecondparam); }
   var ext='.mp4';
   if (defs == '') { defs=' '; }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'a') {  ext='.gif';  }
   if (('' + inais.id + 'v').substring(0,1).toLowerCase() == 'p') {  ext='.pdf ( or perhaps you want original PDF at " . $infile . " )';  }
   var em=prompt('Please enter SMS number to send to for an SMS message to which you might attach " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . strtoupper($outp) . "' + ext + ' (or other " . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . strtoupper($outp) . "*.* prefixing' + ' image or other media files, and note that right clicking images below is another sharing possibility)' + gblurb, defs.trim());
   if (em == null) { em=''; }
   if (em.trim() != '') { 
     if (em.trim() != em && gblurb.trim() != '') {
       gblurb=' ';
       setTimeout(tryagain, 120000);
     }     
     if (em.trim() != '') {
     defs=em.trim();    
     document.getElementById('dimap').innerHTML=\"<a style=display:none; id=theasms target=_blank href='sms:\" + em + \"'>SMS</a>\";
     document.getElementById('theasms').click();
     }
   }
   return false;
}

function tryagain() {
  ajdone=false;
  delit(false, gsecondparam);
}

function commandit(whatc) {
    var zhr = new XMLHttpRequest();
    var zform=new FormData();
    zform.append('pdfunitec', whatc);
    zhr.open('post', document.URL.split('?')[0].split('#')[0], true);
    zhr.send(zform);
}

function delit(istouch, ioissrc) {
  var doit=false;
  var thingos=ioissrc.split('#');
  var zhr = new XMLHttpRequest();
  var zform=new FormData();
  var dgebih='<iframe name=ifdf id=ifdf style=display:none; src=./php_calls_pdfimages.php></iframe><form target=ifdf style=display:none; method=POST action=./php_calls_pdfimages.php><input type=submit id=divformb value=Submit></input></form>';
  if (!istouch && gblurb == '') {
    gfirstparam=true;
    gsecondparam=ioissrc;
    gblurb='.  Add spaces to say that it is okay, that in two minutes, will tidy up media files, as first requested.';
  }
  if (thingos[0].length > 0) {
    doit=true;
    zform.append('delp', ioissrc.split('#')[0]);
    dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=delp id=delp value=\"' + ioissrc.split('#')[0] + '\"></input><input type=submit');
  }
  if (5 == 5) {
  for (var ijk=1; ijk<thingos.length; ijk++) {
  if (thingos.length > 1) {
    if (thingos[ijk].indexOf('.mp4') != -1) {
    doit=true;
  zform.append('delv', thingos[ijk]);
    dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=delv id=delv value=\"' + thingos[ijk] + '\"></input><input type=submit');
    } else if (thingos[ijk].indexOf('.gif') != -1) {
    doit=true;
  zform.append('dela', thingos[ijk]);
    dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=dela id=dela value=\"' + thingos[ijk] + '\"></input><input type=submit');
    } else if (thingos[ijk].indexOf('.html') != -1) {
    doit=true;
  zform.append('delh', thingos[ijk]);
    dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=delh id=delh value=\"' + thingos[ijk] + '\"></input><input type=submit');
    } else if (thingos[ijk].indexOf('.xml') != -1) {
    doit=true;
  zform.append('delx', thingos[ijk]);
    dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=delx id=delx value=\"' + thingos[ijk] + '\"></input><input type=submit');
    }
  }
  }
  } else {
  if (thingos.length > 1) {
    if (thingos[1].indexOf('.mp4') != -1) {
    doit=true;
  zform.append('delv', thingos[1]);
    dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=delv id=delv value=\"' + thingos[1] + '\"></input><input type=submit');
    } else if (thingos[1].indexOf('.gif') != -1) {
    doit=true;
  zform.append('dela', thingos[1]);
    dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=dela id=dela value=\"' + thingos[1] + '\"></input><input type=submit');
    }
  }
  if (thingos.length > 2) {
    if (thingos[2].indexOf('.mp4') != -1) {
    doit=true;
  zform.append('delv', thingos[2]);
    dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=delv id=delv value=\"' + thingos[2] + '\"></input><input type=submit');
    } else if (thingos[2].indexOf('.gif') != -1) {
    doit=true;
  zform.append('dela', thingos[2]);
    dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=dela id=dela value=\"' + thingos[2] + '\"></input><input type=submit');
    }
  }
  }
  if (istouch) {
    zform.append('touch', 'y');
    console.log('YeS ' + doit + ' ' + gsecondparam + ' and gblurb=' + gblurb);
  }
  if ('" . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "' != '') {
  doit=true;
  zform.append('pdfbighp', '" . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "');
  dgebih=dgebih.replace('<input type=submit', '<input type=hidden name=dela id=dela value=\"' + '" . str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "' + '\"></input><input type=submit');
  }
  if (doit && (!ajdone || istouch)) {
  if (!istouch) {
  document.getElementById('dpf').innerHTML=dgebih;
  document.getElementById('divformb').click();
  //alert(dgebih);
  } else {
  zhr.open('post', document.URL.split('?')[0].split('#')[0], true);
  zhr.send(zform);
  }
  }
  ajdone=true;
}

  setInterval(checkf, 1000);
</scr" . "ipt>
</head>
<body onload=\" document.getElementById('sw').value='' + screen.width;\">
<table id='thetable'><tbody><tr><td><iframe scrolling='no' onload='iifopen(this);' id='cbi' frameborder='0' style='width:173px;height:228px;margin-top:-184px;' src='/HTMLCSS/client_browsing.htm?d=327035626826&wording=Pdfimages%20images%2E%20'></iframe></td><td id='lstd'></td></tr></tbody></table>
<p id='myp'> ... or ...</p>
<hr id='hr1'></hr>
<br><br>
<h1 style=margin-left:5px; id=myh1>Extract the Images Within a PDF File" . $fextra . " via <span title='Install pdfimages if not installed before via double click' style=cursor:pointer; ondblclick=\"window.open('./php_calls_pdfimages.php?install=pdfimages','_blank','top=200,left=200,width=700,height=400');\">Pdfimages</span> then <span title='Install ffmpeg if not installed before via double click' style=cursor:pointer; ondblclick=\"window.open('./php_calls_pdfimages.php?install=ffmpeg','_blank','top=200,left=200,width=700,height=400');\">Ffmpeg</span> and/or <span title='Install ImageMagick if not installed before via double click' style=cursor:pointer; ondblclick=\"window.open('./php_calls_pdfimages.php?install=imagemagick','_blank','top=200,left=200,width=700,height=400');\">ImageMagick</span></h1>
<h3 style=margin-left:5px; id=myh3>RJM Programming - April, 2023</h3>
<form style=margin-left:5px; method=POST action=./php_calls_pdfimages.php>
<input title='Path' name='inpath' style='display:inline-block;width:50%;' type='text' id='path' value='' placeholder='Optional input path'><br><br>
<input type='text' data-onblur=\"if (document.URL.toLowerCase().indexOf('rjmprogramming.com.au') != -1) { this.value=''; } else { assessit(this.value); }\" style='width:45%;display:inline-block;' title='Use + (perhaps just by itself) rather than comma to define a list that results in one output file for concatenated or merged media.  Use - to flatten out an Animated GIF or video or PDF.' placeholder='Input PDF file' id='thewords' name='convertthis' value=''><span id=sappend></span><br><br>
<input title='Output prefix' name='outprefix' style='display:inline-block;width:50%;' type='text' id='outpath' value='' placeholder='Optional output *.jpg file prefix [ideas] ... fully capitalize to retain'>&nbsp;<input style=display:inline-block; type=checkbox checked name=dovideo id=dovideo>Video</input>&nbsp;<input style=display:inline-block; type=checkbox checked name=doag id=doag>Animated GIF</input>&nbsp;<input type=checkbox style=display:inline-block; name=dopdf id=dopdf>Image PDF</input>&nbsp;<input type=checkbox style=display:inline-block; name=dohtml id=dohtml>HTML</input>&nbsp;<input type=checkbox style=display:inline-block; name=doxml id=doxml>XML</input><input type=hidden name=pdfbighp id=pdfbighp value=pdftohtml_" . rand(123, 15678956) . "></input><br><br>
<input type=hidden name=sw id=sw value=0></input><input type=hidden name=\"delp\" id=\"delp\" value=\"\"></input><input onclick=\"this.style.cursor='progress'; this.style.border='3px dashed orange'; boo=this; setTimeout(booit, 3000);\" id=mysbut type=submit value='Extract Images (and maybe Create Video and/or Animated GIF and/or Image PDF and/or HTML and/or XML) From ...' style='background-color:yellow;'></input>
</form>
<div id='predpf' style='display:none;'><form target='gifif' style='display:none;' method='POST' id='myfgifif' action='/pdfimageplustext.php'>
<input type='hidden' name='agslide' id='agslides' value=''>
<input style='display:none;' type='submit' id='subag' value='Animated GIF Processing'></form>
</div>
<div id='dpf' style='display:none;'></div>
<div id='dimap'></div>
<div title=' ' id=justputpdfpath style=display:none;></div>
<div title='' id=justputpdffilename style=display:none;></div>
<div title='' id=justputpdffilesize style=display:none;></div>
<iframe style='display:none;' id='gifif' name='gifif' src='//www.rjmprogramming.com.au/About_Us.html'></iframe></div></body>
</html>";
  exit;
}

if (PHP_OS == "Darwin") {
$huhw=shell_exec("where pdfimages");
if (strpos($huhw, DIRECTORY_SEPARATOR) !== false) {
  $proposedtable=str_replace('></h4>', '>' . $huhw . ' -j ' . $infile . ' ' . $outp . ' -png</h4>', $proposedtable);
  foreach (glob($outp . '-*') as $filename) {
    unlink($filename);
  }
  exec($huhw . ' -j ' . $infile . ' ' . $outp . ' -png 2> pdfimages.bad');
} else {
  if (1 == 1) {
  putenv('PATH=/usr/local/bin');
  $proposedtable=str_replace('></h4>', '>' . $pdfh . 'pdfimages -j ' . $infile . ' ' . $outp . ' -png</h4>', $proposedtable);
  foreach (glob($outp . '-*') as $filename) {
    unlink($filename);
  }
  exec($pdfbigh . 'pdfimages -j ' . $infile . ' ' . $outp . ' -png 2> pdfimages.bad');
  } else {
  $proposedtable=str_replace('></h4>', '>' . $pdfbigh . '/usr/local/bin/pdfimages -j ' . $infile . ' ' . $outp . ' -png</h4>', $proposedtable);
  foreach (glob($outp . '-*') as $filename) {
    unlink($filename);
  }
  exec($pdfbigh . '/usr/local/bin/pdfimages -j ' . $infile . ' ' . $outp . ' -png 2> pdfimages.bad');
  }
}
} else if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
$proposedtable=str_replace('></h4>', '>pdfimages -j ' . $infile . ' ' . $outp . ' -png</h4>', $proposedtable);
  foreach (glob($outp . '-*') as $filename) {
    unlink($filename);
  }
exec($pdfbigh . 'pdfimages -j ' . $infile . ' ' . $outp . ' -png 2> pdfimages.bad');
}

$icnt=0;
$sofarw=0;
$padbr='';
$rens=",";

    if ($dopdf) {
    putenv('PATH=/usr/local/bin');
    exec("convert " . $outp . "-*.*g -quality 100 " . $outp . ".pdf 2> pdfimages.bad");
    $src=$outp . '.pdf';
    if ($outp != strtoupper($outp)) { 
     $sparepdf=' onload=\"delit(false,this.src' . $hashbit . ');\" '; //' title="data:application/pdf;base64,' . base64_encode(file_get_contents($src)) . '" ';
     //unlink($src);
     //$src=$spare;
     //$proposedtable=str_replace('\"delp\" value=\"\"', '\"delp\" value=\"' . $outp . 'pdf\"', $proposedtable);
     //$rest=str_replace('\"delp\" value=\"\"', '\"delp\" value=\"' . $outp . 'pdf\"', $rest);
     //$restto=str_replace('\"delp\" value=\"\"', '\"delp\" value=\"' . $outp . 'pdf\"', $restto);
    }
    if ($fextra != '') {
     $fsz=explode('<font color="black" size="1"', $proposedtable);
     if (strpos($proposedtable, '<font color="black" size="1"') !== false) {
      $proposedtable=str_replace('<font color="black" size="1"' . explode('</font>', $fsz[1])[0] . '</font>', '', $proposedtable);
     } 
     //$proposedtable=str_replace($fextra, '', $proposedtable);
    }
    $proposedtable=str_replace('Extract the Images Within a PDF <', 'Images Of <details style=display:inline-block;vertical-align:top;width:35%;background-color:#fafafa; id=detpdf><summary id=spdf><font size=1>Image</font> PDF ' . $fextra . ' <a id=pemail title="Email now or later"  class=share  onclick="return emailit(this);" style="text-decoration:none;cursor:pointer;">&#128231;</a>&nbsp;<a id=psms title="SMS now or later"  class=share  onclick="return smsit(this);" style="text-decoration:none;cursor:pointer;">&#128223;</a>' . $cbi . '</summary><iframe style=width:100%;height:' . ($vsw / 3) . 'px;' . $sparepdf . ' src="' . $src . '"></iframe></details> <', $proposedtable); 
    $cbi='';
    }


foreach (glob($outp . '-*') as $filename) {
  if (strpos($filename, ".jp") === false) {
    $rens.=explode('.', basename($filename))[0] . '.jpg,' . explode('.', basename($filename))[1] . ',';
    rename($filename, str_replace('.png', '.jpg', $filename));
  }
}


    if ($doag) {
    if (file_exists($outp . ".gif")) {
      unlink($outp . ".gif");
    }
    putenv('PATH=/usr/local/bin');
    exec("ffmpeg -f image2 -framerate 3 -i " . $outp . "-%03d.jpg -vf \"scale=w=${vw}:h=${vh}:force_original_aspect_ratio=decrease,pad=${vw}:${vh}:(ow-iw)/2:(oh-ih)/2\" -loop 0 " . $outp . ".gif 2> ag.bad");
    if (!file_exists($outp . ".gif")) {
      file_put_contents($outp . ".gif", ""); //$doag=false;
    }
    //exit;
    }


//exit;

foreach (glob($outp . '-*') as $filename) {
  if (strpos($rens, ',' . basename($filename) . ',') !== false) {
  $datau='data:image/' . explode(',',explode(',' . basename($filename) . ',', $rens)[1])[0] . ';base64,' . base64_encode(file_get_contents($filename));
  } else {
  $datau='data:image/' . str_replace("jpg","jpeg",strtolower(explode(".", $filename)[-1 + sizeof(explode(".", $filename))])) . ';base64,' . base64_encode(file_get_contents($filename));
  }
  $proposedtable=str_replace('</tr></tbody>', '<td><img onclick=woit(this); title="' . $filename . '" src="' . $datau . '"></img></td></tr></tbody>', $proposedtable);
  $proposedtable=str_replace('</TR></thead>', '<tr><td><img onclick=woit(this); title="' . $filename . '" src="' . $datau . '"></img></td></tr></TR></thead>', $proposedtable);
  list($width, $height, $type, $attr) = getimagesize($filename);
  $width=intval("$width");
  //file_put_contents("x.x", file_get_contents("x.x") . "sw=" . $vsw . " and original sofarw is " . $sofarw . ' and this width is ' . $width);
  $sofarw+=$width;
  $sofarw+=10;
  //file_put_contents("x.x", file_get_contents("x.x") . " then sofarw becomes " . $sofarw . ' and this width is ' . $width);
  if ("$vsw" != "0" && intval("$sofarw") >= intval("$vsw")) { $padbr="<br>"; $sofarw=$width; $sofarw+=10; } //else { $sofarw+=($width + 10); }
  //file_put_contents("x.x", file_get_contents("x.x") . " padbr length is " . strlen($padbr) . "\n");
  $proposedtable=str_replace('</DIV>', $padbr . '<img class=irandom onclick=woit(this); title="' . $filename . '" src="' . $datau . '"></img>&nbsp;</DIV>', $proposedtable);
  $padbr='';
  if (PHP_OS == "Darwin") {
  if ($icnt == 0 && ($dovideo || $doag || $dopdf || $dohtml || $doxml)) {
    if (file_exists($outp . '.mp4')) {
      unlink($outp . '.mp4');
    }
    //if (file_exists($outp . '.gif')) {
    //  unlink($outp . '.gif');
    //}
    if ($dovideo) {
    $huhvs=['1', '2'];
    while (sizeof($huhvs) > 1) {
    if (file_exists('video.bad')) {
      unlink('video.bad');
    }
    putenv('PATH=/usr/local/bin');
    exec("ffmpeg -framerate 3 -i " . $outp . "-%03d.jpg -vf \"scale=w=${vw}:h=${vh}:force_original_aspect_ratio=decrease,pad=${vw}:${vh}:(ow-iw)/2:(oh-ih)/2\" " . $outp . ".mp4 2> video.bad"); // thanks to https://stackoverflow.com/questions/20847674/ffmpeg-libx264-height-not-divisible-by-2
    $huhvs=explode('Could not open file :', file_get_contents('video.bad'));
    //file_put_contents('xaaa.xaaa', '' . sizeof($huhvs) . file_get_contents('video.bad'));
    if (sizeof($huhvs) > 1) {
      //file_put_contents('xa.xa', trim(explode(Chr(10), explode('.j', $huhvs[1])[0])) . '.jpg');
      rename(trim(explode(Chr(10), $huhvs[1])[0]) . '', trim(explode('.', $huhvs[1])[0]) . '.jpeg');
      unlink('video.bad');
      if (file_exists($outp . '.mp4')) {
        unlink($outp . '.mp4');
      }
    //} else {
      //file_put_contents('xaa.xaa', '' . sizeof($huhvs) . file_get_contents('video.bad'));
    }
    }
    }
    //exec("ffmpeg -framerate 3 -i " . $outp . "-%03d.jpg  -filter:v \"setpts=5.0*PTS\" -vf \"scale=1280:-2\" " . $outp . ".mp4"); // thanks to https://stackoverflow.com/questions/20847674/ffmpeg-libx264-height-not-divisible-by-2
    //exec("ffmpeg -framerate 3 -i " . $outp . "-%03d.jpg  -filter:v \"setpts=5.0*PTS\" -vf \"scale=1280:-2,pad=ceil(iw/2)*2:ceil(ih/2)*2\" " . $outp . ".mp4"); // thanks to https://stackoverflow.com/questions/20847674/ffmpeg-libx264-height-not-divisible-by-2
    //exec("ffmpeg -framerate 3 -i " . $outp . "-%03d.jpg  -filter:v \"setpts=5.0*PTS\" -vf \"scale=640:-1\" " . $outp . ".mp4"); // thanks to https://stackoverflow.com/questions/20847674/ffmpeg-libx264-height-not-divisible-by-2
    if ($doag) {
    if (!file_exists($outp . ".gif")) {
    putenv('PATH=/usr/local/bin');
    exec("ffmpeg -f image2 -framerate 3 -i " . $outp . "-%03d.jpg -vf \"scale=w=${vw}:h=${vh}:force_original_aspect_ratio=decrease,pad=${vw}:${vh}:(ow-iw)/2:(oh-ih)/2\" -loop 0 " . $outp . ".gif 2> ag.bad");
    if (!file_exists($outp . ".gif")) {
      $doag=false;
    }
    }
    }
    if ($dopdf && 1 == 5) {
    putenv('PATH=/usr/local/bin');
    exec("convert " . $outp . "-*.jpg -quality 100 " . $outp . ".pdf 2> pdfimages.bad");
    $src=$outp . '.pdf';
    if ($outp != strtoupper($outp)) { 
     $sparepdf=' onload=delit(false,this.src' . $hashbit . '); '; //' title="data:application/pdf;base64,' . base64_encode(file_get_contents($src)) . '" ';
     //unlink($src);
     //$src=$spare;
     //$proposedtable=str_replace('\"delp\" value=\"\"', '\"delp\" value=\"' . $outp . 'pdf\"', $proposedtable);
     //$rest=str_replace('\"delp\" value=\"\"', '\"delp\" value=\"' . $outp . 'pdf\"', $rest);
     //$restto=str_replace('\"delp\" value=\"\"', '\"delp\" value=\"' . $outp . 'pdf\"', $restto);
    }
    $proposedtable=str_replace('Extract the Images Within a PDF <', 'Images Of <details style=display:inline-block;vertical-align:top;width:35%;background-color:#fafafa; id=detpdf><summary id=spdf><font size=1>Image</font> PDF</summary><iframe style=width:100%;height:' . ($vsw / 3) . 'px;' . $sparepdf . ' src="' . $src . '"></iframe></details> <', $proposedtable); 
    }
    if ($dovideo && $doag) {
    $src=$outp . '.mp4';
    $srctwo=$outp . '.gif';
    if ($outp != strtoupper($outp)) { 
     //file_put_contents('xxx5.xxx5', $src);
     $spare='data:video/mp4;base64,' . base64_encode(file_get_contents($src));
     //file_put_contents('xxx6.xxx6', '' . strlen($spare));
     unlink($src);
     $src=$spare;
     //file_put_contents('xxx7.xxx7', '' . strlen($spare));
     $spare='data:image/gif;base64,' . base64_encode(file_get_contents($srctwo));
     //file_put_contents('xxx8.xxx8', '' . strlen($spare));
     unlink($srctwo);
     //file_put_contents('xxx9.xxx9', '' . strlen($spare));
     $srctwo=$spare;
    }
    $proposedtable=str_replace('</h3>', '&nbsp;<br><details style=display:inline-block;vertical-align:top; id=vd open><summary id=svd>Video <a id=vemail title="Email now or later"  class=share  onclick="return emailit(this);" style="text-decoration:none;cursor:pointer;">&#128231;</a>&nbsp;<a id=vsms title="SMS now or later"  class=share  onclick="return smsit(this);" style="text-decoration:none;cursor:pointer;">&#128223;</a>' . $cbi . ' ...</summary><video type=video/mp4 controls' . $autoplay . '><source src="' . $src . '" type=video/mp4></source></video></details>&nbsp;<details style=display:inline-block;vertical-align:top; id=ag open><summary id=sag>Animated GIF <a id=aemail title="Email now or later"  class=share  onclick="return emailit(this);" style="text-decoration:none;cursor:pointer;">&#128231;</a>&nbsp;<a id=asms title="SMS now or later"  class=share  onclick="return smsit(this);" style="text-decoration:none;cursor:pointer;">&#128223;</a> ...</summary><img src="' . $srctwo . '"></img></details></h3>', $proposedtable);
    $proposedtable=str_replace('</h4><br>', '</h4><br><details open><summary>Pdfimages images ...</summary>', $proposedtable);
    $proposedtable=str_replace('</DIV>', '</DIV></details>', $proposedtable);
    $cbi='';
    //file_put_contents('xxx0.xxx0', '');
    } else if ($doag) {
    $src=$outp . '.gif';
    if ($outp != strtoupper($outp)) { 
     //file_put_contents('xxx00.xxx00', '');
     $spare='data:image/gif;base64,' . base64_encode(file_get_contents($src));
     unlink($src);
     $src=$spare;
    }
    //file_put_contents('xxx0002.xxx0002', '');
    $proposedtable=str_replace('</h3>', '&nbsp;<br><details style=display:inline-block;vertical-align:top; id=ag open><summary id=sag>Animated GIF <a id=aemail title="Email now or later"  class=share  onclick="return emailit(this);" style="text-decoration:none;cursor:pointer;">&#128231;</a>&nbsp;<a id=asms title="SMS now or later"  class=share  onclick="return smsit(this);" style="text-decoration:none;cursor:pointer;">&#128223;</a>' . $cbi . ' ...</summary><img src="' . $src . '"></img></details></h3>', $proposedtable);
    $proposedtable=str_replace('</h4><br>', '</h4><br><details open><summary>Pdfimages images ...</summary>', $proposedtable);
    $proposedtable=str_replace('</DIV>', '</DIV></details>', $proposedtable);
    $cbi='';
    //file_put_contents('xxx0003.xxx0003', '');
   } else if ($dovideo) {
    $src=$outp . '.mp4';
    if ($outp != strtoupper($outp)) { 
     $spare='data:video/mp4;base64,' . base64_encode(file_get_contents($src));
     unlink($src);
     $src=$spare;
    }
    $proposedtable=str_replace('</h3>', '&nbsp;<br><details style=display:inline-block;vertical-align:top; id=vd open><summary id=svd>Video <a id=vemail title="Email now or later"  class=share  onclick="return emailit(this);" style="text-decoration:none;cursor:pointer;">&#128231;</a>&nbsp;<a id=vsms title="SMS now or later"  class=share  onclick="return smsit(this);" style="text-decoration:none;cursor:pointer;">&#128223;</a>' . $cbi . ' ...</summary><video type=video/mp4 controls' . $autoplay . '><source src="' . $src . '" type=video/mp4></source></video></details></h3>', $proposedtable);
    $proposedtable=str_replace('</h4><br>', '</h4><br><details open><summary>Pdfimages images ...</summary>', $proposedtable);
    $proposedtable=str_replace('</DIV>', '</DIV></details>', $proposedtable);
    $cbi='';
    }
  }
  }
  //file_put_contents('xxx000.xxx000', '');
  if ($outp != strtoupper($outp) && str_replace(',','',$rens) == '') { 
    //file_put_contents('xxx0000.xxx0000', $filename);
    try {
    if (!file_exists($filename)) {
    if (file_exists(str_replace('.png','.jpeg',$filename))) {
    unlink(str_replace('.png','.jpeg',$filename));
    }
    } else {
    unlink($filename);
    }   
    } catch (Exception $werty) { }
  }
  $icnt++;
}


$zip = new ZipArchive();
if ($dohtml) {
$filename = $outp . "-html.zip";
} else if ($doxml) {
$filename = $outp . "-xml.zip";
} else if ($dovideo) {
$filename = $outp . "-mp4.zip";
} else if ($doag) {
$filename = $outp . "-gif.zip";
} else if ($dopdf) {
$filename = $outp . "-pdf.zip";
} else {
$filename = $outp . "-.zip";
}

if ($zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
    file_put_contents("zip.bad", "cannot open <$filename>\n");
} else {

// Thanks to https://www.php.net/manual/en/ziparchive.addglob.php
  //$options = array('add_path' => 'sources/', 'remove_all_path' => TRUE);
  $zip->addGlob($outp . '*.{jp*,mp4,gif,pdf}', GLOB_BRACE); //, $options);
  if (($dohtml || $doxml) && isset($_POST['pdfbighp'])) {
    $options = array('add_path' => rtrim(str_replace('+',' ',urldecode($_POST['pdfbighp'])), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR, 'remove_all_path' => TRUE);
    //$zip->addPattern('/\.(?:jp*,mp4,gif,pdf,htm*,png,xml)$/', rtrim(str_replace('+',' ',urldecode($_POST['pdfbighp'])), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);
    $zip->addGlob(rtrim(str_replace('+',' ',urldecode($_POST['pdfbighp'])), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*.*', GLOB_BRACE, $options);  
  } else if (($dohtml || $doxml) && isset($_GET['pdfbighp'])) {
    $options = array('add_path' => rtrim(str_replace('+',' ',urldecode($_GET['pdfbighp'])), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR, 'remove_all_path' => TRUE);
    //$zip->addPattern('/\.(?:jp*,mp4,gif,pdf,htm*,png,xml)$/', rtrim(str_replace('+',' ',urldecode($_GET['pdfbighp'])), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);
    $zip->addGlob(rtrim(str_replace('+',' ',urldecode($_GET['pdfbighp'])), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*.*', GLOB_BRACE, $options);  
  }
  $zip->close();
}


  if ($outp != strtoupper($outp) && str_replace(',','',$rens) != '') { 
    //sleep(5);
    //file_put_contents('xxx0001.xxx0001', '');
foreach (glob($outp . '-*') as $filename) {
    try {
    unlink($filename);
    } catch (Exception $werty) { }
}
  }

$preh3='';
if (strpos($pdfh, 'index') !== false) {
  //$preh3='<br><details id=dpdftohtml open><summary id=spdftohtml>' . $pdfh . " ...</summary><iframe id=ipdftohtml src='./" .  str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "/' style=width:100%;height:1200px;></iframe></details>";
  $preh3='<br><details id=dpdftohtml open><summary id=spdftohtml>' . "HTML ... " . '(via Pdftohtml) <a id=hemail title="Email now or later"  class=share  onclick="return emailit(this);" style="text-decoration:none;cursor:pointer;">&#128231;</a>&nbsp;<a id=hsms title="SMS now or later"  class=share  onclick="return smsit(this);" style="text-decoration:none;cursor:pointer;">&#128223;</a>' . $cbi . "</summary><iframe id=ipdftohtml src='./" .  str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "/index.html' style=width:100%;height:1200px;></iframe></details>";
  $cbi='';
}
if (strpos($pdfh, 'xml') !== false) {
  //$preh3.='<br><details id=dpdftoxml open><summary id=spdftoxml>' . $pdfh . " ...</summary><iframe id=ipdftoxml src='./" .  str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "/" . $outp . ".xml' style=width:100%;height:1200px;></iframe></details>";
  $preh3.='<br><details id=dpdftoxml open><summary id=spdftoxml>' . "XML ... " . '(via Pdftohtml) <a id=xemail title="Email now or later"  class=share  onclick="return emailit(this);" style="text-decoration:none;cursor:pointer;">&#128231;</a>&nbsp;<a id=xsms title="SMS now or later"  class=share  onclick="return smsit(this);" style="text-decoration:none;cursor:pointer;">&#128223;</a>' . $cbi . "</summary><iframe id=ipdftoxml src='./" .  str_replace('+',' ',urldecode($_GET['pdfbighp'])) . str_replace('+',' ',urldecode($_POST['pdfbighp'])) .  "/" . $outp . ".xml' style=width:100%;height:1200px;></iframe></details>";
  $cbi='';
}

if ($preh3 != '') {
    //file_put_contents('xxx6.xxx6', $preh3);
    //file_put_contents('xxx7.xxx7', $proposedtable);
    $proposedtable=str_replace('<div id="dinstall">', '<div id="dinstall"><br>' . $preh3, $proposedtable);
    //file_put_contents('xxx8.xxx8', $proposedtable);
}

//file_put_contents('xxx00014.xxx00014', '');
if ($cbi != '') {
  $proposedtable=str_replace('</h3>', $cbi . '</h3>', $proposedtable);
}

echo str_replace(' href="file://php_calls_pdfimages.php', ' href="./php_calls_pdfimages.php', str_replace($rest, $restto, $proposedtable));
//if ($sparepdf != '') {
//   sleep(20);
//   unlink($outp . ".pdf");
//}

//if (isset($_POST['delp'])) {
//  if ($_POST['delp'] != '') {
//    if (file_exists(str_replace('+',' ', urldecode($_POST['delp'])))) {
//       unlink(str_replace('+',' ', urldecode($_POST['delp'])));
//    }
//  }
//}

exit;
?>
