<?php
    session_start(); 
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/check.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link href="css/admin.css" rel="stylesheet" type="text/css">
		<title>无标题文档</title>
	</head>

	<body>
<?PHP

			
	$ls=$_POST['ls'];
	$id=$_POST['id'];
	
	$downloadTitle=$_POST['downloadTitle'];
	if($downloadTitle=="")
	{
		echo "<script>alert('请填写标题！');history.go(-1);</script>";
		break;
	}
	$ChangecatePagePic=$_POST['ChangecatePagePic'];
	$image=$_FILES['downloadName']['name'];   
  $size=$_FILES['downloadName']['size'];   
  $type=$_FILES['downloadName']['type'];
  
  //echo "名字：".$image."<br>";
  //echo "大小：".$size."<br>";
  //echo "类型：".$type."<br>";
	
	
	
	switch ($ls)
	{
		case "insert":
			//if ($type == "application/octet-stream" || $type == "application/vnd.ms-excel" || $type == "application/msword" )
			//	{
				 if($size < $PicSize) //开始判断图像大小
					{
						$pathBigPic="../".$downloadFolders;
							//echo $pathBigPic."<br>";
							//创建大图文件夹
						createFolder($pathBigPic);
																			
						$arr=array(" ",".");   
						//产生文件名   
						$productPic=str_replace($arr ,"",time()).".".substr($image,-3);
						
						$pathBigPic=$pathBigPic."/".$productPic;
						//echo $pathBigPic."<br>";
						//上传文件
						move_uploaded_file($_FILES['downloadName']['tmp_name'], $pathBigPic);
						
						$select_sql2="select * from ls_download ";
						$select_query2=$opendb->query($select_sql2);
						$select_rows2=mysql_num_rows($select_query2); //总数
						
						$insert_sql=sprintf("insert into ls_download(downloadTitle,downloadName,downloadSize,enable,Num) values(%s,%s,%s,%s,%s)",
						GetSQLValueString($downloadTitle, "text"),
						GetSQLValueString($productPic, "text"),
						GetSQLValueString($size, "int"),
						
						GetSQLValueString("1", "int"),
						GetSQLValueString(($select_rows2+1), "int"));
						$insert_query=$opendb->query($insert_sql);
						echo "<script>location='download.php';</script>";
				
					}						
				 else
					{
						echo "	<script>alert('文件大小超过了限制，最大只能上传".$PicSize."K的文件！');history.go(-1);</script>";
					}
			//	}
			//else
			//	{
			//		 echo "	<script>alert('请选择文件上传，或者你选择的文件不符合要求!\\n只允许格式 .rar .docs .xls');history.go(-1);</script>";
			//	}
			
			break;
		
	
		case "update":
					
					  if($ChangecatePagePic=="yes")
	  				 	{
	  				 		//判断格式
	  				 		//if ($type == "application/octet-stream" || $type == "application/vnd.ms-excel" || $type == "application/msword" )
								//		{
											if($size < $PicSize) //开始判断图像大小
											{
													  $pathBigPic="../".$downloadFolders;
						
						
															$arr=array(" ",".");   
													  	//产生文件名   
													  	$pic=$_POST['Pic'];
													  	$pic=trim(str_replace(substr($image,-4),"",$pic));
													  	//echo $pic;
													  	$productPic=str_replace($arr ,"",$pic).".".substr($image,-3);
													  														  	
													  	$pathBigPic=$pathBigPic."/".$productPic;
													  	//echo $pathBigPic;
													  	//上传文件
													  	move_uploaded_file($_FILES['productPic']['tmp_name'], $pathBigPic);
													  	
													  		
								}
											else
											{
												echo "	<script>alert('文件大小超过了限制，最大只能上传".$PicSize."K的文件！');history.go(-1);</script>";
											}
										//}
										//else
										//{
											// echo "	<script>alert('请选择文件上传，或者你选择的文件不符合要求!\\n只允许格式 .rar .docs .xls');history.go(-1);</script>";
										//}
	  				 	} 
	  				 								if($size=="")
	  				 								{
	  				 								$update_sql=sprintf("update ls_download set downloadTitle=%s where ID=%s",
																									  GetSQLValueString($downloadTitle, "text"),
																										GetSQLValueString($id, "int")
																								);
															}
															else
															{
															$update_sql=sprintf("update ls_download set downloadTitle=%s, downloadSize=%s where ID=%s",
																									  GetSQLValueString($downloadTitle, "text"),
																									  GetSQLValueString($size, "int"),
																										GetSQLValueString($id, "int")
																								);
															}
															
														  //echo $update_sql;
														  //更新数据
														  $update_query=$opendb->query($update_sql);
														  echo "<script>alert('数据更新成功!');location='download.php';</script>";
				
		break;	
	}

?>
	</body>
</html>