// 10 digit max 2000000000 timestamp to basis 64 string iK34Xj.jpg ( 0-9 A-Z a-z [10+26+26 , are 62 pices , plus 2 =: ] _ § [are 64 pices] )
um webcam-bilder und den timestamp in einem kurzen (12X4G6.jpeg) dateinamen zu speichern , habe ich mal ein test script mit input-formular geschrieben
input: timestamp oder zahl im decimal system
output: zahlensystem zwischen 2 .. 64 (0-9 A-Z a-z ~ #)
es funktioniert , ist doch aber sicher schon oft VIEL ELEGANTER veroeffentlicht
FRAGE: wonach sollte ich wo suchen , um ein ordentliches program fuer diesen zweck zu finden , timestamp AND filename zB brachte nix
	
							
						
					um webcam-bilder und den timestamp in einem kurzen (12X4G6.jpeg) dateinamen zu speichern , habe ich mal ein test script mit input-formular geschrieben
input: timestamp oder zahl im decimal system
output: zahlensystem zwischen 2 .. 64 (0-9 A-Z a-z ~ #)
es funktioniert , ist doch aber sicher schon oft VIEL ELEGANTER veroeffentlicht
FRAGE: wonach sollte ich wo suchen , um ein ordentliches program fuer diesen zweck zu finden , timestamp AND filename zB brachte nix
PHP-Code:
	
	
<html>
<head>
<title>tim2cod</title>
</head>
<body>
<?php 
// qq66yy tim2cod  jpegname 0-9 A-Z a-z _ § [are 62 pices]
// test   [url]http://nb/book_ph5_MyS4/Kapitel4/formulare/kontaktform0007.php[/url]
// echo " . . tim2cod: $tim2cod . . vor form" ; 
// default
//$dnum=64; // possible 2..64
//$lenn=6;  // default 8 
//$digit63 = "§" ;
//$digit62 = "_" ;
//$testecho = 0 ; // default = 0 ; try  5 .. 10
$timstamlong = date("Ymd_His");
$timstam = time() ;  //   / 1000 ; // ; // 
echo $timstam ;
if (!$issend && !$tim2cod) // aus formular variable name="tim2cod" 
{
          // method="POST"
?>
    <form method="GET" action="<?php echo $PHP_SELF ?>">
      timstamp(max 2000000000): <input type="text" name="tim2cod" value="188288" size="22"><br/>
      dnum(def 62) 2..64: <input type="text" name="dnum" value="62"size="16"><br/>
      digits len(def 6): <input type="text" name="lenn" value="6" size="8"><br/>
      digit62: <input type="text" name="digit62" value="_" size="8"><br/>
      digit63: <input type="text" name="digit63" value="~" size="8"><br/> 
      addfirstchars: <input type="text" name="addfirstchar" value="" size="8">.JPEGNAME.jpg (if you wanna add same leading chars)<br/> 
      testecho(def 0): <input type="text" name="testecho" value="0" size="8"> try 3 . . 9  <br/>
        <input type="submit" name="submit" value="GO">
        <input type="hidden" name="issend" value="1">
      </p>
    </form>
<?php
}
 // echo "<br /> ^ 94, ° 176, @ 64, ! 33, § 167, $ 36, + 43, - 45, ~ 126, # 35, _ 95, € 128, | 124, ß 223 <br>" ;
 // ___|0:48|9:57=48+|A:65|Z:90_ 11..35=55+|a:97|z:122_ 36..$dnum=61+|___ 
//$digit63 = "§" ;
//$digit62 = "_" ;
function timstam2cod($t4, $dnum, $lenn, $digit62, $digit63 , $addfirstchar ="" )
{ 
  // need $digit62 = '_' ; $digit63 = '§' ;
  // $t4=$timsta2;
  // echo "<br /> ^ 94, ° 176, @ 64, ! 33, § 167, $ 36, + 43, - 45, ~ 126, # 35, _ 95, € 128, | 124, ß 223 <br>" ;
    if ( 2000000000 < $t4 ){ // 10 digits need 
        echo " . . . error in func timstam2cod () NUMBER TO BIG $t4 . . . " ;
    }
  
  while ( $lenn-- > 0 )   
  { $t1=$t4; // last ganzzahl
    $t2=$t1 % $dnum;  // rest , letzte DIGIT
    $t3=$t1 - $t2; // t3 teilt dann ganzzahlig
    $t4= $t3 / $dnum; // t4 is ganzzahl
    // echo " . . t2=$t2 . . " ;
    if     ($t2 == 63){$t5= $digit63 ;}    // for last two 64 and 63 no more letters echo "t2=$t2 t5=$t5 digit63:$digit63" ; 
    else if($t2 == 62){$t5= $digit62 ;}    // so chose ^°@!§$+~#_€|ß+-
    else if($t2 >  35){$t5=chr($t2 + 61  );} // 97='a' 97-36=61 (36..61)to(a..z)
    else if($t2 >   9){$t5=chr($t2 + 55  );} // 65='A' 65-10=55 (10..35)to(A..Z)
    else              {$t5=chr($t2 + 48  );} // 48='0' 48-0=48 (0..9)to(0..9)
    $jpnam=$t5.$jpnam; // // ___|0:48|9:57=48+|A:65|Z:90_ 11..35=55+|a:97|z:122_ 36..$dnum=61+|___ 
    if($testecho > 4)echo "<br/>$jpnam timstam2cod";
  }
  if ($addfirstchar) $jpnam = $addfirstchar.$jpnam  ;
  if($testecho > 4)echo " [ ret $jpnam ] ";
  return $jpnam ;
} // end function timstam2cod($timstam)
    if($testecho > 8){  echo "<br /> ^ 94, ° 176, @ 64, ! 33, § 167, $ 36, + 43, - 45, ~ 126, # 35, _ 95, € 128, | 124, ß 223 <br />" ;
            echo "<br /> ^" . ord('^') ;
            echo "<br />° " . ord('°') ;
            echo "<br />@ " . ord('@') ;
            echo "<br /> !" . ord('!') ;
            echo "<br /> §" . ord('§') ;
            echo "<br /> $" . ord('$') ;
            echo "<br /> +" . ord('+') ;
            echo "<br /> -" . ord('-') ;
            echo "<br /> ~" . ord('~') ;
            echo "<br /> #" . ord('#') ;
            echo "<br /> _" . ord('_') ;
            echo "<br /> €" . ord('€') ;
            echo "<br /> |" . ord('|') ;
            echo "<br /> ß" . ord('ß') ;
            echo "<br /> " . ord('') ;
            echo "<br /> "  ;
     }
     if($testecho > 6){
            echo " timstamlong is $timstamlong ";
            echo " timstam is $timstam <br/>";
    }
$jpnam = timstam2cod($tim2cod, $dnum, $lenn , $digit62, $digit63 , $addfirstchar );  //   $lenn = strlen( st4 ) ; $lenn nu.
$ss=0; // reverse time to code
///////////////////////////////////////////////////////////////200
// only for test the function timstam2cod() say if(1){ . . } to see , if it get code to timestamp back , and work right
// need $dnum 0..64 default=62 // $lenn how much digits // $digit62 $digit63 the two spechial chars ,are in:  ^°@!§$+~#_€|ß+-
function cod2timstam( $jpnam , $dnum , $addfirstchar ="" ) // ( $jpnam , $dnum , $lenn =0 // default = 8) default = 8
{ 
  $jpnalll = " " .$jpnam. "" ; // maybe convert to a string
  $lllen = strlen( $jpnalll ) - 1 ; // for the added leading " " SPACE
  
   if ( $addfirstchar > ''){
      $addfirslll = " " . $addfirstchar. "" ; // maybe convert to a string
      $addfirstclllen = strlen( $addfirslll ) -1 ;  // for the added leading " " SPACE
      
      $jpnam = substr( $jpnam, $addfirstclllen ) ; // remove leading $ addfirstchar
   }
   
   $ss= 0 ; // reverse time to code
   $lllen = strlen(" " .$jpnam. "") -2 ; // is already without $ addfirstchar
   $l = $lllen + 1 ;
  while($l--  > 0)   
  { 
    // in while schon -1 nit wie c++ ka
    $letr=substr($jpnam, $lllen - $l, 1); // in while schon -1 nit wie c++ ka // $letr=substr($jpnam,7-$l,1); // in while schon -1 nit wie c++ ka
    $zif= ord($letr); // den buchstaben zahlen ascii zu 0 bis 63 reduzieren
    if     ($zif == ord($digit63) ){ $zif = 63 ;} // 63 for last two 62 and 63 no more letters
    else if($zif == ord($digit62) ){ $zif = 62 ;} // 62 so chose ^°@!§$+~#_€|ß+-
    else if($zif >              96){ $zif = $zif -  61 ;} // 97='a' 122='z' 97-36=61 (36..61)to(a..z)
    else if($zif >              64){ $zif = $zif -  55 ;} // 65='A'  90='Z' 65-10=55 (10..35)to(A..Z)
    else                           { $zif = $zif -  48 ;} // 48='0'  57='9' 48-0=48 (0..9)to(0..9)
    
        //~ if      (($zif >    47) && ($zif <    58)) { $zif = $zif -  48 ;} // 48='0'  57='9' 48-0=48 (0..9)to(0..9)
        //~ else if (($zif >    64) && ($zif <    91)) { $zif = $zif -  55 ;} // 65='A'  90='Z' 65-10=55 (10..35)to(A..Z)
        //~ else if (($zif >    96) && ($zif <   123)) { $zif = $zif -  61 ;} // 97='a' 122='z' 97-36=61 (36..61)to(a..z)
        //~ else if ($zif == ord($digit62) )           { $zif = 62 ;} // 62 for last two 62 and 63 no more letters
        //~ else                                       { $zif = 63 ;} // 63 so chose ^°@!§$+~#_€|ß+- default '_' and '#'
    $ss= $ss * $dnum + $zif   ; // so is potenz automatisch beim next aufruf
    // 
    if($testecho > 6)echo "<br />$l: letr: $letr , zif: $zif , restore: $ss ";
  } 
  //
  if($testecho > 4)echo " [ ret. $ss ] " ;
  if($testecho > 7)echo " . . jpnalll: $jpnalll . . len: $lllen  . .<br>" ;
  return $ss ;
}// function cod2timstam( $jpnam , $dnum , $lenn )
//////////////////////////////////////////////////////////////////////200
$timrevbac = cod2timstam( $jpnam , $dnum ,$addfirstchar ) ;
$sucsesss = ' NOT GOOD ERROR ' ;
if( $tim2cod == $timrevbac )  $sucsesss = 'OK! :-)' ;
echo "<br/><br/>
 <b>JpgNam: </b> $jpnam<br>
 <b> timstam2cod(): </b> $tim2cod <br />
 <b> cod2timstam( ): </b> $timrevbac    <b> REVERSE $sucsesss </b> <br /> 
 <b>dnum(def 62): </b> $dnum<br>
 <b>lenn(def 6): </b> $lenn<br>
 addfirstchars .>$addfirstchar<.
 <form method=POST action=$PHP_SELF>
 <input type='submit' name='submit' value='NEW TEST?'>
 </form>
";
?>
</body>
</html>