Location: PHPKode > projects > Nail Streaming Server > nailss_v12/includes/misc.php
<?php
function bannedFiles($in)
{
	$in = strtolower($in);
	switch($in)
	{
		case "thumbs.db":
			return true;
		case ".htaccess":
			return true;
		case ".directory":
			return true;
		case "desktop.ini":
			return true;
		default:
			return false;
	}
}

function numDirs($in)
{
	$dirArray = @scandir($in, 0);
	$diri = 0;
	foreach($dirArray as $single)
	{
		if(is_dir($in."/".$single."/") && $single != "." && $single != "..")
		{
			$diri++;
		}
		elseif(is_link($in."/".$single."/"))
		{
			$diri++;
		}
	}	
	return $diri;
}

function numFiles($in)
{
	$dirArray = @scandir($in, 0);
	$filei = 0;
	foreach($dirArray as $single)
	{
		if(is_file($in."/".$single))
		{
			$filei++;
		}
	}	
	return $filei;
}

function customEncodeURL($in)
{
	$in = str_replace("+", "%2B", $in);
	$in = str_replace("&", "%26", $in);
	$in = str_replace("'", "%27", $in);
	$in = str_replace("!", "%21", $in);
	$in = str_replace(" ", "%20", $in);
	$in = str_replace(",", "%2C", $in);
	$in = str_replace("\\", "", $in);
	//$in = urlencode($url);
	return $in;
}

function connect_to($host, $user, $pass, $db)
{
	$connection = @mysql_connect($host, $user, $pass) or die ("Could not connect to   mysql<br>");
	$select = @mysql_select_db($db, $connection) or die ("Could not select database<br>");
	return $connection;
}

function cidr($ip_addr_cidr) 
{
	$ip_arr = explode('/', $ip_addr_cidr);
	
	$dotcount = substr_count($ip_arr[0], ".");
	$padding = str_repeat(".0", 3 - $dotcount);
	$ip_arr[0].=$padding;
	
	$bin = '';
	for($i=1;$i<=32;$i++) 
	{
		$bin .= $ip_arr[1] >= $i ? '1' : '0';
	}
	$ip_arr[1] = bindec($bin);
	
	$ip = ip2long($ip_arr[0]);
	$nm = ip2long($ip_arr[1]);
	$nw = ($ip & $nm);
	$bc = $nw | (~$nm);
	
	$y = 0;
	for ($x = ($nw + 1); $x <= ($bc); $x++)
	{
		$returnVal[$y] = long2ip($x);
		$y++;
	}
	return $returnVal;
}

function killcifs($musicDir)
{
	$dirArray = @scandir($musicDir, 0);
	foreach($dirArray as $single)
	{
		//If you have your files mounted via Samba and its creating CIFS files, this will clean them up
		if(substr($single, 0, 4) == "cifs" && (strlen($single) == 8 || strlen($single) == 7))
		{
			unlink($musicDir."/".$single);
		}
	}
}

function crawl($musicDir, $dir)
{
$musicDir = $musicDir.$dir."/";

$dirArray = @scandir($musicDir, 0);

$filei = 0;
$diri = 0;
$imagei = 0;
foreach($dirArray as $single)
{
	if(is_file($musicDir.$single) && !bannedFiles($single))
	{
		$fnamearray = explode(".", $single);
		$num = count($fnamearray);
		$ftype = strtolower($fnamearray[$num-1]);
		
		if($ftype == "jpg" || $ftype == "gif" || $ftype == "png" || $ftype == "bmp")
		{
			//do nothing
		}
		elseif($ftype == "m3u" || $ftype == "sfv" || $ftype == "cue")
		{
			//do nothing
		}
		else
		{
			$fileList[$filei] = $single;
			$filei++;
		}
	}
	elseif(is_dir($musicDir.$single) && $single != "." && $single != "..")
	{
		$dirList[$diri] = $single;
		$diri++;
	}
	elseif(is_link($musicDir.$single))
	{
		$dirList[$diri] = $single;
		$diri++;
	}
}
if(isset($dirList))
{
	foreach($dirList as $single)
	{
		crawl($musicDir, $single);
	}
}
if(isset($fileList))
{
	$sql0 = "DELETE FROM `files` WHERE `Directory` = '$musicDir'";
	@mysql_query($sql0);
	foreach($fileList as $single)
	{
		$sql1 = "INSERT INTO `files` (`Directory`, `File`) VALUES ('$musicDir', '$single')";
		@mysql_query($sql1);
	}
}
echo( "$musicDir crawled<br>" );
}
?>
Return current item: Nail Streaming Server