`
yujicun
  • 浏览: 1715 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
文件上传格式判断 PHP判断上传文件类型(防修改后缀)
<?php   

function file_type($filename)
{
    $file = fopen($filename, "rb");
    $bin = fread($file, 2); //只读2字节
    fclose($file);
    $strInfo = @unpack("C2chars", $bin);
    $typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
    $fileType = '';
    switch ($typeCode)
    {
        case 7790:
            $fileType = 'exe';
            break;
        case 7784:
            $fileType = 'midi';
            break;
        case 8297:
            $fileType = 'rar';
            break;        
		case 8075:
            $fileType = 'zip';
            break;
        case 255216:
            $fileType = 'jpg';
            break;
        case 7173:
            $fileType = 'gif';
            break;
        case 6677:
            $fileType = 'bmp';
            break;
        case 13780:
            $fileType = 'png';
            break;
        default:
            $fileType = 'unknown: '.$typeCode;
    }

	//Fix
	if ($strInfo['chars1']=='-1' AND $strInfo['chars2']=='-40' ) return 'jpg';
	if ($strInfo['chars1']=='-119' AND $strInfo['chars2']=='80' ) return 'png';

    return $fileType;
}

echo file_type('start.php');   // 6063 or 6033
js获取地址中的参数 js http://yujicun.iteye.com
//http://localhost/myhome.html?home_id=123
var home_id='';
	function getURLc(home_id)
	{
		var home_id='';
		var url=window.location.search;
		if(url.indexOf("?")!=-1)   
		{   
		  var str   =   url.substr(1)   
		  strs = str.split("&");   
		  for(i=0;i<strs.length;i++)   
		  {   
		    if([strs[i].split("=")[0]]=='home_id'){
				home_id=unescape(strs[i].split("=")[1]);
			} 
		  }   
		}
		return home_id;
	}

js找到数组中重复的元素 js, 找到数组中重复的元素
<SCRIPT LANGUAGE="JavaScript">
<!--
	var arr = ["2","a","a","b"]
var obj = {}
for(var i=0;i<arr.length;i++)
{
	var item = arr[i];
	if(obj[item]==null)obj[item] = 1;
	else obj[item] = obj[item]+1;
	}

	for(a in obj)
	{
	var item = obj[a];
	if(item>1)alert("重复元素"+a)
} 
//-->
</SCRIPT>
计算代码执行时间的类
run_time.php  Code:

<?php
class runtime
{
var $StartTime = 0;
var $StopTime = 0;

function get_microtime()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}

function start()
{
$this->StartTime = $this->get_microtime();
}

function stop()
{
$this->StopTime = $this->get_microtime();
}

function spent()
{
return round(($this->StopTime - $this->StartTime) * 1000, 1);
}

}
?>

return_time_test.php  Code:

<?php
include ('run_time.php');

$runtime = new runtime;
$runtime->start();

$a = 0;
for ($i=0;$i<rim(1000000);$i++){
$a += $i;
}
$runtime->stop();
echo "页面执行时间:".$runtime->spent()."毫秒!";
?>
Global site tag (gtag.js) - Google Analytics