<?php
    session_start(); 
	require_once('../../../../ru/update/2.55/ls_admin/inc/conn.php');
	require_once('../../../../ru/update/2.55/ls_admin/inc/constant.php');
	require_once('../../../../ru/update/2.55/ls_admin/inc/ls_syscode.php');
	require_once('../../../../ru/update/2.55/ls_admin/inc/check.php');
	$opendb=new mydb();
	require_once('../../../../ru/update/2.55/ls_admin/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="../../../../ru/update/2.55/ls_admin/css/admin.css" rel="stylesheet" type="text/css">
<title>无标题文档</title>
</head>
<body>
<?
	$itemnoprefix=$_POST['itemnoprefix'];
	$productname=$_POST['productname'];
	$id=$_POST['id'];//类别id
	$thisBigPicW=$_POST['thisBigPicW'];
	$thisBigPicH=$_POST['thisBigPicH'];
	$opendb=new mydb();
	$productSpecification=htmlspecialchars($_POST['productSpecification'], ENT_QUOTES);
	$showonhome=0;
	$j=1;
	for($i=0;$i<$BatchFiles;$i++) 
	{
			$select_sql2="select * from ls_products where productID=".$id." ";
			$select_query2=$opendb->query($select_sql2);
			$select_rows2=mysql_num_rows($select_query2); //总产品数
			$no=$select_rows2+1;
			$productItemNo=$itemnoprefix.$no;
			$productName=$productname;
			$file=$_FILES['userfile']['tmp_name'][$i];
			if($file=="") 			//文件不存在就找下一个
			{continue;}
			
			list($width, $height, $type, $attr) = getimagesize("$file");
			$image=$_FILES['userfile']['name'][$i];;   
  			$size=filesize($file);   
			$pathFoldersProducts="../".getproductfolder($id);
			if ($type ==1  || $type ==2  || $type ==3  )//1="image/gif" 2="image/png" 3="image/pjpeg"
			{
				 if($size < $PicSize) //开始判断图像大小
				{
					$pathBigPic=$pathFoldersProducts."/".$BigFoldersProducts;
					//echo $pathBigPic."<br>";
					//创建大图文件夹
					createFolder($pathBigPic);
					$pathSmallPic=$pathFoldersProducts."/".$SmallFoldersProducts;
					//echo $pathSmallPic."<br>";
					//创建小图文件夹
					createFolder($pathSmallPic);
					$pathPagePic=$pathFoldersProducts."/".$showproductsFolders;
					//echo $pathSmallPic."<br>";
					//创建大图浏览（.htm）文件夹
					createFolder($pathPagePic);
						
					
					$arr=array(" ",".");   
					//产生文件名   
					$picfilename=time()*100+$j;
					$productPic=str_replace($arr ,"",$picfilename).".".substr($image,-3);
					//echo $productPic;
					$pathBigPic=$pathBigPic."/".$productPic;
					//上传文件
					move_uploaded_file($file, $pathBigPic);
					
					$srcFile=$pathBigPic; //源地址
					$toW=$SmallPicW;			//宽度
					$toH=$SmallPicH;			//高度
					$toFile=$pathSmallPic."/".$productPic; //目标地址
					//生成缩略图
					ImageResize($srcFile,$toW,$toH,$toFile);
					if($width>$thisBigPicW||$height>$thisBigPicH)//大图超过预定长宽，缩小
					{
						$toW=$thisBigPicW;
						$toH=$thisBigPicH;
						$srcFile=$pathBigPic;
						$toFile=$pathBigPic;
						ImageResize($srcFile,$toW,$toH,$toFile);
					}
					$insert_sql=sprintf("insert into ls_products 						(productPic,productItemNo,productName,productSpecification,productID,Num,showOnHome,enable) values (%s,%s,%s,%s,%s,%s,%s,%s) ",
							GetSQLValueString($productPic, "text"),
							GetSQLValueString($productItemNo, "text"),
							GetSQLValueString($productName, "text"),
							GetSQLValueString($productSpecification, "text"),
							GetSQLValueString($id, "int"),
							GetSQLValueString($select_rows2+1, "int"),
							GetSQLValueString($showonhome, "int"),
							GetSQLValueString("1", "int")
						 );
						//echo $insert_sql;
						//添加数据
						$insert_query=$opendb->query($insert_sql);
					}
				
		}
	echo "生成： ".$j.". ".$pathBigPic."<br/><br/>";
	$j++;

	}//end while
	echo "<br/><a href=\"cate.php\">返回</a>";
	$opendb->close();
?>
</body>
</html>
