<?php
include("require.php");
if($core_file=="1" && !isset($_COOKIE["core_user_name"]) || $core_file=="0")
  jump("error.php?id=2");
if($_GET["action"]=="upload")
{
  $oldname=$_FILES["file"]["name"];
  $fileextensionname=strtolower(eregi_replace(".+(\..+)","\\1",$oldname));
  $filename = time().random(4).$fileextensionname;
  if($_FILES["file"]["error"]>0)
  {
    ?>
	  <div style="width:70px; float:left; text-align:left; font-size:12px;">上传附件:</div>
	  <div id="file" style="float:left; text-align:left; padding:2px; font-size:12px;">上传失败 <a href="upload.php">重新上传</a></div>
	<?php
  }
  elseif(!eregi($core_filetype,$fileextensionname))
  {
    ?>
	  <div style="width:70px; float:left; text-align:left; font-size:12px;">上传附件:</div>
	  <div id="file" style="float:left; text-align:left; padding:2px; font-size:12px;">上传的文件类型不被容许 <a href="upload.php">重新上传</a></div>
	<?php
  }
  elseif(($_FILES["file"]["size"]/1024)>$core_filesize)
  {
    ?>
	  <div style="width:70px; float:left; text-align:left; font-size:12px;">上传附件:</div>
	  <div id="file" style="float:left; text-align:left; padding:2px; font-size:12px;">上传的文件大小超过限制 <a href="upload.php">重新上传</a></div>
	<?php
  }
  else
  {
    $directory=date('Y-m');
	if(!file_exists('upload/'.$directory))
	  mkdir("upload/".$directory, 0777);
	move_uploaded_file($_FILES["file"]["tmp_name"],"upload/".$directory."/".$filename);
	$username=$_SERVER['REMOTE_ADDR'];
	if(isset($_COOKIE["core_user_name"]))
	  $username=$_COOKIE["core_user_name"];
	$time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
	$type=1;//主题图片附件标识
	if(!preg_match( '/^image\//i ',$_FILES["file"]["type"])) 
      $type=3;//主题回复附件标识
	$phpcolor->table="upload";
    $phpcolor->field="oldfilename,filename,filesize,filetype,username,uptime,type";
	$phpcolor->where="'".$oldname."','".$directory."/".$filename."','".$_FILES["file"]["size"]."','".$type."','".$username."','".$time."','0'";
    $phpcolor->write();
	$fileid=mysql_insert_id();
	echo "<input type=hidden value=".$fileid." id=imgurl>";
	echo "<script>if (parent.document.getElementById('file').value==''){parent.document.getElementById('file').value=document.getElementById('imgurl').value;}else{parent.document.getElementById('file').value=parent.document.getElementById('file').value+'|'+document.getElementById('imgurl').value;}</script>";
	echo "<script>parent.document.getElementById('filelbl').style.display=''</script>";
	echo "<script>parent.document.getElementById('filelb').style.display=''</script>";
	echo "<script>parent.document.getElementById('filelbl').innerHTML=parent.document.getElementById('filelbl').innerHTML+'<br /><br />'</script>";
	echo "<script>if (parent.document.getElementById('filelb').innerHTML==''){parent.document.getElementById('filelb').innerHTML='<div>".$oldname." (附件大小：".(round($_FILES["file"]["size"]/1024, 2))."KB) 收取<select id=\"jflx\"><option value=\"1\" selected>积分</option><option value=\"2\">余额</option></select>：<input id=\'fsj\' type=\'text\' class=\'box1\' size=\'3\' value=\'0\' />点/元</div>';}else{parent.document.getElementById('filelb').innerHTML=parent.document.getElementById('filelb').innerHTML+'<div>".$oldname." (附件大小：".(round($_FILES["file"]["size"]/1024, 2))."KB) 收取<select id=\"jflx\"><option value=\"1\" selected>积分</option><option value=\"2\">余额</option></select>：<input id=\'fsj\' type=\'text\' class=\'box1\' size=\'3\' value=\'0\' />点/元</div>'}</script>";
	?>
	  <div style="width:70px; float:left; text-align:left; font-size:12px;">上传附件:</div>
	  <div id="file" style="float:left; text-align:left; padding:2px; font-size:12px;">附件上传成功 <a href="upload.php">继续上传</a></div>
	<?php	
  }
}
else
{
?>
<script>
function test()
{
  document.getElementById("file").style.display = 'none';
  document.getElementById("filets").style.display = 'block';
}
</script>
<form action="upload.php?action=upload" method="post" enctype="multipart/form-data" style="max-height:30px;">
<div style="height:3px; overflow:hidden">&nbsp;</div>
<div style="width:70px; float:left; text-align:left; font-size:12px;">上传附件:</div>
<div style="float:left;" id="file"><input type="file" size="40" name="file" style="width:370px; height:20px; border:#DCE1E7 1px solid;"/>&nbsp;<input type="submit" onclick="test();" value="上传" /></div>
<div style="float:left; display:none" id="filets"><img src="images/<?php echo $core_style; ?>/uploadfile.gif" width="350" height="15" /></div>
</form>
<?php
}
?> 