⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functions_base.inc.php

📁 一款文件上传程序
💻 PHP
字号:
<?php
function gpc($n,$w='GPC',$d=''){for($i=0;$i<strlen($w);$i++){if($w[$i]=='G'&&isset($_GET[$n]))return$_GET[$n];if($w[$i]=='P'&&isset($_POST[$n]))return$_POST[$n];if($w[$i]=='C'&&isset($_COOKIE[$n]))return$_COOKIE[$n];}return$d;}
function strip_gpc($v){if(is_array($v)){while(list($k,$x)=each($v))$v[$k]=strip_gpc($x);return$v;}return stripslashes($v);}
function str_slice($s,$l){return strlen($s)>$l?substr($s,0,$l/2-1).'...'.substr($s,-($l/2-2)):$s;}
function path_encode($p){return rawurlencode(trim(str_replace('//','/',$p),' /.'));}
function path_decode($p){return str_replace('../','',trim(rawurldecode($p),' /.'));}
function clean_url($u){return str_replace(' ','%20',trim(str_replace('//','/',$u),' '));}
function rtrim2($s,$c=' /\"'){for($i=strlen($s)-1;$i>=0&&strstr($c,$s[$i]);$i--){if(strstr($c,$s[$i])){$s=substr($s,0,$i);}}return $s;}
function go_to($url=''){exit(header('Location: '.($url===''?(isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'index.php'):$url)));}
function get_size($s,$u='B',$p=1){$us=array('B'=>'KB','KB'=>'MB','MB'=>'GB','GB'=>'TB');return (($u!=='B')&&(!isset($us[$u]))||($s<1000))?(number_format($s,$p)."&nbsp;$u"):(get_size($s/1024,$us[$u],$p));}
function make_file($f){if(!touch($f))exit('Unable to create '.$f);return change_mode($f);}
function change_mode($f,$m=0777){$o=umask(0);$r=chmod($f,$m);umask($o);return$r;}
function make_dir($p,$m=0777){$o=umask(0);$r=mkdir($p,$m);umask($o);return$r;}
function get_rand($len=8,$p=''){$c='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';$x=strlen($c)-1;for($i=0;$i<$len;$i++)$p.=$c[mt_rand(0,$x)];return$p;}
function get_filename($f){if(false!==($pos=strrpos($f,'.')))return substr($f,0,$pos);return$f;}
function get_extension($n){return strtolower(trim(strrchr($n,'.'),'.'));}
function multi_sort($arr,$c,$o=SORT_ASC,$t=SORT_STRING,$case=false){reset($arr);$tmp=array();while(list($k,$v)=each($arr)){if(!isset($v[$c]))break;$tmp[$k]=(!$case&&$t==SORT_STRING)?strtolower($v[$c]):$v[$c];}if(count($tmp))array_multisort($tmp,$o,$t,$arr);return$arr;}
function parse($str,$var,$val=''){if(is_array($var)){while(list($k,$v)=each($var))$str=str_replace( $k,$v,$str);return$str;}return str_replace($var,$val,$str);}

function dir_name($p){return rtrim2(dirname($p),'./ ');}
function delete_dir($p){if(false!==($h=@opendir($p))){while(false!==($f=readdir($h))){if($f=='.'||$f=='..') continue;if(is_dir($p.'/'.$f)){delete_dir($p.'/'.$f);}else{unlink ( $p . '/' . $f );}}closedir($h);return rmdir($p);}return false;}
function is_image($f){$fp=@fopen($f,'rb');if(!$fp)return false;$hd=fread($fp,8);fclose($fp);return$hd=="\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"||substr($hd,0,2)=="\xFF\xD8"||substr($hd,0,3)=='GIF';}
function is_zip($f){$fp=@fopen($f,'rb');if(!$fp)return false;$hd=fread($fp,4);fclose($fp);return$hd=="\x50\x4B\x03\x04";}
function check_path($b,$p){if(strpos($p,'../')!==false)return false;$b=realpath($b);$p=realpath($p);if(strlen($b)>strlen($p))return false;return $b==substr($p,0,strlen($b));}
function ascii_str($e){$r='';for($i=0;$i<strlen($e);$i++)$r.='&#'.ord($e[$i]).';';return$r;}
function send_email ( $to, $subject, $message, $headers = '', $params = '' )
{
	if ( !@mail ( $to, $subject, $message, $headers, $params ) )
	{
		print "Unable to send email, server is probably not configured. Mail content:\r\n<br /><br />";
		print '<pre>' . $message . '</pre>';
	}
}

function parse_bb ( $str )
{
	$search = array
	(
		'#\[B\](.+?)\[\/B\]#mis',
		'#\[I\](.+?)\[\/I\]#mis',
		'#\[U\](.+?)\[\/U\]#mis',
		'#\[COLOR\=(.+?)\](.+?)\[\/COLOR\]#mis',
		'#\[URL\](.+?)\[\/URL\]#mis',
		'#\[URL\=(.+?)\](.+?)\[\/URL\]#mis',
		'#\[IMG\](.+?)\[\/IMG\]#mis',
	);

	$replace = array
	(
		'<strong>$1</strong>',
		'<span style="font-style:italic;">$1</span>',
		'<span style="text-decoration:underline;">$1</span>',
		'<span style="color:$1;">$2</span>',
		'<a href="$1">$1</a>',
		'<a href="$1">$2</a>',
		'<img src="$1" alt="" />',
	);

	return preg_replace ( $search, $replace, $str );
}

function get_folder_info ( $p )
{
	if(!is_dir($p))return false;
	$f = $p . '/.folder.php';
	$db = new DB;
	if ( $db->open ( $f ) )
	{
		$info = $db->all();
		$db->close();
		return $info;
	}
	// For folders created before 6.1
	$info = array
	(
		'is_public'		=> is_file ( $p . '/.public' ),
		'is_gallery' 	=> false,
		'icon'			=> '',
		'description' => is_file ( $p . '/.description' ) ? implode ( '', file ( $p . '/.description' ) ) : ''
	);
	if ( $db->create ( $f ) )
	{
		$db->open ( $f );
		$db->set ( $info, 1 );
		$db->save();
	}
	@unlink ( $p . '/.public' );
	@unlink ( $p . '/.description' );

	return $info;
}

function set_folder_info ( $p, $info )
{
	if(!is_dir($p))return false;
	$f = $p . '/.folder.php';
	$db = new DB;

	if ( !is_file ( $f ) && !$db->create ( $f ) )
	{
		return false;
	}

	if ( $db->open ( $f ) )
	{
		$db->set ( $info, 1 );
		$db->save();
		return true;
	}
	return false;
}

function is_folder_empty ( $path )
{
	if ( false === ( $h = @opendir ( $path ) ) ) return false;
	$ignore=array('.','..','.cache.php','.folder.php','thumbs');
	while ( false !== ( $f = readdir ( $h ) ) )
	{
		if(in_array($f,$ignore))continue;
		return false;
	}
	return true;
}

function has_public_folders ( $path )
{
    $contents = get_contents ( $path );
    $folders = &$contents['dirs'];
    $count = count ( $folders );
    for ( $i = 0; $i < $count; ++$i )
    {
		$info = get_folder_info ( $path . '/' . $folders[$i]['path'] );
		if ( $info !== false && $info['is_public'] ) return true;
    }
    return false;
}

function clear_contents_cache($dir){return@unlink($dir.'/.cache.php');}

function get_contents ( $dir, $ret = array ( ), $parent = '', $level = 0 )
{
	$ignore=array('.','..','.cache.php','.folder.php');
    if(!count($ret))$ret=array('dirs'=>array(array('name' =>'<MAIN_FOLDER>','path'=>'','level'=>0,'size'=>0)),'files'=>array(),'total_dirs'=>0,'total_files'=>0,'total_size'=>0);
	$cache_file=$dir.'/.cache.php';
	if($level==0){$DB=new DB;if($DB->open($cache_file)){return$DB->all();}}
	$fidx = $parent==''?'<MAIN_FOLDER>':$parent;

	if ( false !== ( $h = @opendir ( $dir ) ) )
	{
		$ret['files'][$fidx] = array ( );
		$index = count($ret['dirs'])-1;
		$ret['dirs'][$index]['files'] = 0;
		$ret['dirs'][$index]['size'] = 0;
		while ( false !== ( $f = readdir ( $h ) ) )
		{
			if(in_array($f,$ignore))continue;

			if(is_dir($dir.'/'.$f))
			{
				$path = trim($parent.'/'.$f,'/');
				$ret['total_dirs']++;
				$ret['dirs'][]=array('name'=>$f,'path'=>$path,'level'=>$level,'size'=>0);
				$ret=get_contents($dir.'/'.$f,$ret,$path,$level+1);
			}
			else
			{
				$size=filesize($dir.'/'.$f);
				$ret['total_files']++;
				$ret['total_size']+=$size;
				$ret['dirs'][$index]['size'] += $size;
				$ret['dirs'][$index]['files']++;
				$ret['files'][$fidx][]=array('name'=>$f,'size'=>$size,'date'=>filemtime($dir.'/'.$f),'is_image'=>(int)is_image($dir.'/'.$f));
			}
		}
		closedir($h);

		if($level==0)
		{
			$DB=new DB;
			if($DB->create($cache_file)&&$DB->open($cache_file))
			{
				$DB->set($ret,1);
				$DB->save();
			}
		}
	}
	return $ret;
}
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -