<?php 
function dirToArray($dir) { 
   $result = array(); 
   $cdir = scandir($dir); 
   foreach ($cdir as $key => $value) 
   { 
      if (!in_array($value,array(".","..","index.php","media.js"))) 
      { 
         if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) 
         { 
            $result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value); 
         } 
         else 
         { 
            $result[] = $value; 
         } 
      } 
   } 
   
   return $result; 
} 

function get_ip( $host ){ 
  $hostip = @gethostbyname( $host ); 
  $ip = ( $hostip == $host ) ? $host : long2ip( ip2long( $hostip ) ); 
  //echo sprintf("Resolved %s to %s", $host, $ip); 
  return $ip;
}

$valami = dirToArray(".");

//$myfile = fopen("media.js", "w+") or die("Unable to open file!");
$myfile = fopen("media.js", "w+");

//$txt = "John Doe\n";
//fwrite($myfile, $txt);
//$txt = "Jane Doe\n";
//fwrite($myfile, $txt);

//$ip = gethostbyname('www.example.com');
//echo $ip;

$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);

echo $hostname;

if (strstr($remoteIP, ', ')) {
    $ips = explode(', ', $remoteIP);
    $remoteIP = $ips[0];
}

echo gethostname();
echo php_uname('n');

foreach($valami as $value) { 
  echo "<a href=http://192.168.15.99/media/film/kep/$value target=_blank>$value</a><br />"; 
  fwrite($myfile, $value);
  fwrite($myfile, "\n");
}

fclose($myfile);

?> 
