www.gusucode.com > HadSky PHP轻论坛系统源码 v2.4.2源码程序 > ytqlt_v2.4.2.0701/phpscript/uploadhead.php

    <?php
if (!defined('puyuetian'))
	exit('Not Found puyuetian!Please contact QQ632827168');

if ($_G['USER']['ID'] == 2 || !$_G['USER']['ID'] || !chkUserQx($_G['USER']['QUANXIAN'], 'uploadhead')) {
	$_G['HTMLCODE']['TIP'] = "您所在的用户组不允许上传文件";
	$_G['HTMLCODE']['TIPJS'] = "top.document.getElementById('div_upload').style.visibility='hidden';";
	template('htmltip');
	exit ;
} else {
	if ($verifycode == $_SESSION['VERIFYCODE_UPLOADFILE']) {
		$_SESSION['VERIFYCODE_UPLOADFILE'] = '';
		if ($_FILES['file']['error'] > 0) {
			$_G['HTMLCODE']['TIP'] = "上传文件错误,可能原因:格式错误或文件超过300K";
			template('htmltip');
			exit ;
		}
		if ($_FILES['file']['size'] > 307200) {
			$_G['HTMLCODE']['TIP'] = "上传文件不能超过300K";
			template('htmltip');
			exit ;
		}
		$uploadfilesuffix = strtolower(end(explode('.', $_FILES['file']['name'])));
		if (!in_array($uploadfilesuffix, array('jpg', 'png', 'bmp', 'gif'))) {
			$_G['HTMLCODE']['TIP'] = "不允许的文件后缀:{$uploadfilesuffix},请核对后再上传";
			template('htmltip');
			exit();
		}
		if ($_FILES['file']['type'] != 'image/jpeg' && $_FILES['file']['type'] != 'image/gif' && $_FILES['file']['type'] != 'image/pjpeg' && $_FILES['file']['type'] != 'image/png' && $_FILES['file']['type'] != 'image/bmp') {
			$_G['HTMLCODE']['TIP'] = "上传文件类型错误,仅允许jpg,png,gif,bmp";
			template('htmltip');
			exit ;
		}
		if (is_uploaded_file($_FILES['file']['tmp_name'])) {
			move_uploaded_file($_FILES['file']['tmp_name'], $_G['SYSTEM']['PATH'] . "/userheadimg/{$_G['USER']['ID']}.png");
		} else {
			$_G['HTMLCODE']['TIP'] = '非法请求!';
			template('htmltip');
			exit ;
		}
		echo "
		<script>
			top.document.getElementById('div_upload').style.visibility='hidden';
			top.document.getElementById('ifrmupload').src='index.php?c=orderupload&type=uploadhead&rnd={$RND}';
			alert('上传成功!');
			top.document.getElementById('userimgurl').src='userheadimg/{$_G['USER']['ID']}.png?rnd={$RND}';
			top.document.getElementById('userhead').src='userheadimg/{$_G['USER']['ID']}.png?rnd={$RND}';
		</script>
		";
	} else {
		$_SESSION['UPLOADFILE_VERIFYCODE'] = '';
		$_G['HTMLCODE']['TIP'] = "上传验证码错误,请刷新页面重试";
		template('htmltip');
		exit ;
	}
}
exit ;