<?php	
try
{
	require_once 'app/Mage.php';
	umask(0);
	Mage::app('default');//初始化程序，设置当前店铺
	$store = Mage::app()->getStore('default');
	$requestKind = $_GET["requestKind"];
	//处理版本信息
	$versionInfos = Mage::getVersionInfo();
	$versionNumber = intval($versionInfos['major'].$versionInfos['minor']);
	$versionIsLess17 = true;
	if($versionNumber >= 17)
	{
		//当前版本大于等于1.7版
		$versionIsLess17 = false;
	}
	//授权验证
	$resource = Mage::getSingleton('core/resource'); 	
	$can_continue = true;			
 	/* $user_id = $_GET["user_id"];
	$pwd = $_GET["pwd"];	 
	$sql="SELECT password FROM `".$resource->getTableName('admin_user')."` WHERE username = '".$user_id."'";	
	$read_data= $resource->getConnection('core_read');  	
	$results = $read_data->fetchAll($sql);    
	$rowCount = 0;
	$password = "";
	foreach ($results as $row)      
    {
		$rowCount = $rowCount + 1;
		if($rowCount > 0)
		{
			$password = $row['password'];     
			break;
		}
    }
	if($rowCount=="0")
	{
		echo "0=授权验证失败，用户不存在";
	}
	else
	{
		if($pwd == $password)
		{
			$can_continue = true;			
		}
		else echo "0=授权验证失败，密码错误";
	} */
	if($can_continue)
	{
		if($requestKind == "0")
		{
			//请求客户资料数据
			$customers_id = $_GET["customers_id"];
			$syncAll = $_GET["syncAll"];
			if($customers_id == '')
				$customers_id = 0;	
			if($syncAll == "1")
			{
				//全部同步
				$customers_id = 0;	
			}
			// gt = '>', lt = '<', eq = '='
			$customers = Mage::getModel('Customer/Customer')->getCollection()->addFieldToFilter('entity_id', array('gt' => $customers_id))->setPageSize(100); 
			$select = array();
			foreach($customers as $customer)
			{
				$addresses = $customer->getAddresses();
				$customers_id = $customer->getEntityId();
				$curCustomer = Mage::getModel('customer/customer')->load($customers_id)->getData();  
				$customers_name = $curCustomer['firstname']." ".$curCustomer['lastname'];
				$telephone = "";
				foreach($addresses as $address)
				{
					if($telephone == "")
					{
						$telephone = $address["telephone"];
						break;
					}
				}
				$select[] = array("customers_id"=>$customers_id,
				 "customers_name"=>$customers_name,
				 "email"=>$customer->getEmail(),
				 "tel"=>$telephone,
				 "fax"=>"");
			}
			if($select == null)
				echo "";
			else
				echo json_encode($select); 	
		}
		else if($requestKind == "1")
		{
			//请求订单数据
			$begindate = $_GET["begindate"];
			$syncAll = $_GET["syncAll"];
			$billno = $_GET["billno"];
			if($billno == '')
				$billno = '';		
			if($syncAll == "1")
			{
				//全部同步
				$billno = '';
			}
			$syncByTime = $_GET["syncByTime"];
			if($syncByTime == '')
				$syncByTime = '0';
			$country = Mage::getModel('Directory/Country');
			$product = Mage::getModel('Catalog/Product');		
			$orders = Mage::getModel('Sales/Order')->getCollection();
			if($syncByTime == "0")
			{
				//以最大订单号同步为准，而不是以最近同步的订单最大日期
				$orders->addFieldToFilter('increment_id', array('gt' => $billno)); 
			}
			if($versionIsLess17)
				$orders->addFieldToFilter('created_at', array('gteq' => $begindate)); 
			else
				$orders->addFieldToFilter('TIMESTAMP(created_at)', array('gteq' => $begindate)); 
			if($syncAll == "0")
			{
				//非全部同步情况下，则要求控制每次同步的数量
				$orders->setPageSize(50); 
			}
			$media_product_base_url = Mage::getBaseUrl("media")."catalog/product/";
			//echo $orders->getSelectSql();
			$select = array();
			foreach($orders as $order)
			{
				$shipping_order_id = $order["increment_id"];
				//$shippingAddress = Mage::getModel('sales/order_address')->load($order->getShippingAddressId());				
				$shippingAddress = $order->getShippingAddress();
				$payments = $order->getPaymentsCollection();
				$payment_method = "";
				foreach($payments as $payment)
				{
					if($payment_method == "")
						$payment_method = $payment["method"];
					else
						$payment_method .= " / ".$payment["method"];	
				}
				$store_id = $order["store_id"];
				$store_name = $order["store_name"];
				$customer_name = $order->getCustomerName();	
				$customerIsGuest = false;
				if($customer_name == "Guest")
				{
					$customerIsGuest = true;
				}
				$order_id = $order->getId();
				$entity_type_id = $order["entity_type_id"];				
				
				$email = $order["customer_email"];	
				if(($email == null) || ($email == ""))
				{		
					$customerId = $order->getCustomerId();
					$customer = Mage::getModel('Customer/Customer')->load($customerId);
					$email = $customer->getEmail();// $order["customer_email"];
					$customer->reset();	
					if(($email == null) || ($email == ""))
					{
						$sql = "SELECT value FROM `".$resource->getTableName('sales_order_varchar')."` WHERE entity_id = ".$order_id." AND entity_type_id = ".$entity_type_id." AND attribute_id = 197";	
						$read_data= $resource->getConnection('core_read');  	
						$results = $read_data->fetchAll($sql);    
						if($results)
						{
							foreach ($results as $row)      
							{
								$email = $row['value']; 
								break;
							}						
						}
						if(($email == null) || ($email == ""))
						{
							$email = $order->getCustomerEmail();
						}										
					}
				}
				$currency_code = $order->getOrderCurrencyCode();
				if(($currency_code == null) || ($currency_code == ""))
				{
					$currency_code = $order["order_currency_code"];	
					if(($currency_code == null) || ($currency_code == ""))
					{
						$sql = "SELECT value FROM `".$resource->getTableName('sales_order_varchar')."` WHERE entity_id = ".$order_id." AND entity_type_id = ".$entity_type_id." AND attribute_id = 129";
						$read_data= $resource->getConnection('core_read');  	
						$results = $read_data->fetchAll($sql);    
						if($results)
						{
							foreach ($results as $row)      
							{
								$currency_code = $row['value']; 
								break;
							}						
						}
						else
						{
							$currency_code = $order->getOrderCurrencyCode();
						}			
					}
				}
				
/* 				echo "<br/>";
				echo "field shipping_method = ".$order["shipping_method"]."<br/>";
				echo "getShippingDescription = ".$order->getShippingDescription()."<br/>";
				echo "field shipping_description = ".$order["shipping_description"]."<br/>";
				echo "getShippingMethod = ".$shippingAddress->getShippingMethod()."<br/>";
				echo "------------------------------------------------"; */
				
				$shipping_method = $order->getShippingDescription();
				if(($shipping_method == null) || ($shipping_method == ""))
				{
					$shipping_method = $order["shipping_description"];	
					if(($shipping_method == null) || ($shipping_method == ""))
					{
						$shipping_method = $shippingAddress->getShippingMethod();
						if(($shipping_method == null) || ($shipping_method == ""))
						{
							$shipping_method = $order["shipping_method"];	
						}				
					}
				}
				$ip = $order["remote_ip"];			
				$shipping_order_id = $order["increment_id"];
				$shipping_order_date = $order["created_at"];
				$shipping_to_rate = $order["shipping_amount"];
				$sub_total = $order["subtotal"];
				//$order_total = $order["grand_total"];		
				//$order_total = $order["grand_total"] + $order["discount"];	
				$order_total = $order->getTotalDue();
				if(($order_total == null) || ($order_total == 0))
				{
					$order_total = $order["total_due"];	
					if(($order_total == null) || ($order_total == 0))
					{
						$order_total = $order->getGrandTotal();
						if(($order_total == null) || ($order_total == 0))
						{
							$order_total = $order["grand_total"];
						}
					}
				}
				$tel = $shippingAddress->getTelephone();
				$shipping_postcode = $shippingAddress->getPostcode();
				$shipping_zone = $shippingAddress->getRegion();
				$shipping_city = $shippingAddress->getCity();
				$country_id = $shippingAddress->getCountry_id();
				$shipping_address_1 = $shippingAddress->getStreetFull();		
				$shipping_customer_name = $shippingAddress->getFirstname()." ".$shippingAddress->getLastname();
				if($customerIsGuest)
				{
					//匿名下单时 customer_name = Guest，所以这里调整成收货人
					$customer_name = $shipping_customer_name;
				}
				$curCountry = $country->loadByCode($country_id);
				$shipping_country = $curCountry->getName();
				$order_state = $order["state"];
				foreach($order->getAllVisibleItems() as $item)
				{
					$product_id = $item["product_id"];
					$product->setStoreId($store_id);
					$curProduct = $product->load($product_id);
					
					$product_sku = $curProduct->getSku();
					$product_name = $item["name"];
					$product_model = $curProduct["model"];
					//产品图片
					$product_image_urls = array();
					$product_image_url = $curProduct["image"];
					if(strlen($product_image_url) > 0)
					{		
					    if(($product_image_url <> "no_selection") && ($product_image_url <> "object"))
						{
							$product_image_url = str_replace($media_product_base_url, "", $product_image_url);
							array_push($product_image_urls, $product_image_url);
						}
					}
					$mediaGalleryImages = $curProduct->getMediaGalleryImages();
					if($mediaGalleryImages)
					{
						foreach($mediaGalleryImages as $mediaGalleryImage)
						{
							try
							{
								$product_image_url = str_replace($media_product_base_url, "", $mediaGalleryImage["url"]);
								array_push($product_image_urls, $product_image_url);							
							}
							catch(Exception $e)
							{
							}
						}
					}
					$product_image_urls = array_unique($product_image_urls);
					$product_price = $item["price"];
					$product_qty = $item["qty_ordered"];
					$product_total = $item["base_row_total"];
					//合计产品属性信息
					$product_size = "";
					$productOptions = $item->getProductOptions();
					if($productOptions)
					{
						if(isset($productOptions['attributes_info']))
						{
							foreach($productOptions['attributes_info'] as $itemOption)
							{
								$label = $itemOption["label"];
								$value = $itemOption["value"];
								if($product_size == "")
									$product_size = $label." : ".$value."\r\n  ";
								else
									$product_size .= $label." : ".$value."\r\n  ";
							}
						}
						if(isset($productOptions['options']))
						{
							foreach($productOptions['options'] as $itemOption)
							{
								$label = $itemOption["label"];
								$value = $itemOption["value"];
								if($product_size == "")
									$product_size = $label." : ".$value."\r\n  ";
								else
									$product_size .= $label." : ".$value."\r\n  ";
							}
						}
					}
 					$select[] = array("product_name"=>$product_name,
						 "product_sku"=>$product_sku,
						 "product_model"=>$product_model,
						 "product_size"=>$product_size,
						 "quantity"=>$product_qty,
						 "price"=>$product_price,
						 "total"=>$product_total,
						 "product_image_urls"=>$product_image_urls,
						 "shipping_order_id"=>$shipping_order_id,
						 "customer_name"=>$customer_name,
						 "email"=>$email,
						 "tel"=>$tel,
						 "fax"=>"",
						 "shipping_customer_name"=>$shipping_customer_name,
						 "shipping_company"=>"",
						 "shipping_address_1"=>$shipping_address_1,
						 "shipping_address_2"=>"",
						 "shipping_city"=>$shipping_city,
						 "shipping_postcode"=>$shipping_postcode,
						 "shipping_country"=>$shipping_country,
						 "shipping_zone"=>$shipping_zone,
						 "shipping_method"=>$shipping_method,
						 "payment_method"=>$payment_method,
						 "currency_code"=>$currency_code,
						 "shipping_to_rate"=>$shipping_to_rate,
						 "insurance_premium"=>0,
						 "procedure_fee"=>0,
						 "sub_total"=>$sub_total,		
						 "order_total"=>$order_total,
						 "shipping_order_date"=>$shipping_order_date,	 
						 "ip"=>$ip,	
						 "order_status"=>$order_state,
						 "HasPay"=>0); 
					 
					$curProduct->reset();
				}
				$order->reset();
			}

			if($select == null)
				echo "";
			else
				echo json_encode($select); 	

		}
		else if($requestKind == "2")
		{
			//更新订单状态
			$billno = $_GET["billno"];
			$billState = $_GET["billstate"];	
			$comment = $_GET["comment"];			
			if($billno == '')
			{
				echo "0=没有传递订单号";
			}
			if($billState == '')
			{
				echo "0=没有传递订单状态";
			}		
			else
			{
				$product = Mage::getModel('Catalog/Product');		
				$order = Mage::getModel('sales/order')->loadByIncrementId($billno);
				if($order == null)
				{
					echo "0=网站后台找不到订单号为 ".$billno." 的订单"; //没有记录一定返回空字符串			
				}
				else
				{
					$cur_datetime = date("Y-m-d G:i:s",time());
					$order_status = 0;
					$order_status_str = "";
					switch($billState)
					{
						case 0://Pending - 等待处理
							$order_status = 1;
							$order_status_str = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
							break;
						case 1://Processing - 处理中 
							$order_status = 2;
							$order_status_str = Mage_Sales_Model_Order::STATE_PROCESSING;
							break;
						case 2://Shipped - 已发货
							$order_status = 3;
							$order_status_str = Mage_Sales_Model_Order::STATE_COMPLETE;
							break;
					}
					$comment = urldecode($comment);
					//更新订单状态，但是不发送通知邮件
/* 					if($versionIsLess17)
					{
						//版本小于 Magento 1.7.0.0：
						$order->setStateUnprotected($order_status_str, $order_status_str, $comment, false);
					}
					else
					{ */
						//版本大于等于 Magento 1.7.0.0：
						$order->setData('state', $order_status_str);
						$order->setStatus($order_status_str);
						$history = $order->addStatusHistoryComment($comment, false);
						$history->setIsCustomerNotified(false); 
					//}
					//保存订单
					$order->save();
					echo "1=更新网站后台订单号为 ".$billno." 的订单成功.";
				}			
			}
		}
		else if($requestKind == "3")
		{
			//请求订单数据
			$billno = $_GET["billno"];
			if($billno == '')
				$billno = '';		
			$country = Mage::getModel('Directory/Country');
			$product = Mage::getModel('Catalog/Product');		
			$orders = Mage::getModel('Sales/Order')->getCollection();
			$orders->addFieldToFilter('increment_id', array('=' => $billno)); 
			$media_product_base_url = Mage::getBaseUrl("media")."catalog/product/";
			//echo $orders->getSelectSql();
			$select = array();
			foreach($orders as $order)
			{
				$shipping_order_id = $order["increment_id"];
				//$shippingAddress = Mage::getModel('sales/order_address')->load($order->getShippingAddressId());				
				$shippingAddress = $order->getShippingAddress();
				$payments = $order->getPaymentsCollection();
				$payment_method = "";
				foreach($payments as $payment)
				{
					if($payment_method == "")
						$payment_method = $payment["method"];
					else
						$payment_method .= " / ".$payment["method"];	
				}
				$store_id = $order["store_id"];
				$store_name = $order["store_name"];
				$customer_name = $order->getCustomerName();	
				$customerIsGuest = false;
				if($customer_name == "Guest")
				{
					$customerIsGuest = true;
				}
				$order_id = $order->getId();
				$entity_type_id = $order["entity_type_id"];				
				
				$email = $order["customer_email"];	
				if(($email == null) || ($email == ""))
				{		
					$customerId = $order->getCustomerId();
					$customer = Mage::getModel('Customer/Customer')->load($customerId);
					$email = $customer->getEmail();// $order["customer_email"];
					$customer->reset();	
					if(($email == null) || ($email == ""))
					{
						$sql = "SELECT value FROM `".$resource->getTableName('sales_order_varchar')."` WHERE entity_id = ".$order_id." AND entity_type_id = ".$entity_type_id." AND attribute_id = 197";	
						$read_data= $resource->getConnection('core_read');  	
						$results = $read_data->fetchAll($sql);    
						if($results)
						{
							foreach ($results as $row)      
							{
								$email = $row['value']; 
								break;
							}						
						}
						if(($email == null) || ($email == ""))
						{
							$email = $order->getCustomerEmail();
						}										
					}
				}
				$currency_code = $order->getOrderCurrencyCode();
				if(($currency_code == null) || ($currency_code == ""))
				{
					$currency_code = $order["order_currency_code"];	
					if(($currency_code == null) || ($currency_code == ""))
					{
						$sql = "SELECT value FROM `".$resource->getTableName('sales_order_varchar')."` WHERE entity_id = ".$order_id." AND entity_type_id = ".$entity_type_id." AND attribute_id = 129";
						$read_data= $resource->getConnection('core_read');  	
						$results = $read_data->fetchAll($sql);    
						if($results)
						{
							foreach ($results as $row)      
							{
								$currency_code = $row['value']; 
								break;
							}						
						}
						else
						{
							$currency_code = $order->getOrderCurrencyCode();
						}			
					}
				}
				
/* 				echo "<br/>";
				echo "field shipping_method = ".$order["shipping_method"]."<br/>";
				echo "getShippingDescription = ".$order->getShippingDescription()."<br/>";
				echo "field shipping_description = ".$order["shipping_description"]."<br/>";
				echo "getShippingMethod = ".$shippingAddress->getShippingMethod()."<br/>";
				echo "------------------------------------------------"; */
				
				$shipping_method = $order->getShippingDescription();
				if(($shipping_method == null) || ($shipping_method == ""))
				{
					$shipping_method = $order["shipping_description"];	
					if(($shipping_method == null) || ($shipping_method == ""))
					{
						$shipping_method = $shippingAddress->getShippingMethod();
						if(($shipping_method == null) || ($shipping_method == ""))
						{
							$shipping_method = $order["shipping_method"];	
						}				
					}
				}
				$ip = $order["remote_ip"];			
				$shipping_order_id = $order["increment_id"];
				$shipping_order_date = $order["created_at"];
				$shipping_to_rate = $order["shipping_amount"];
				$sub_total = $order["subtotal"];
				//$order_total = $order["grand_total"];		
				//$order_total = $order["grand_total"] + $order["discount"];	
				$order_total = $order->getTotalDue();
				if(($order_total == null) || ($order_total == 0))
				{
					$order_total = $order["total_due"];	
					if(($order_total == null) || ($order_total == 0))
					{
						$order_total = $order->getGrandTotal();
						if(($order_total == null) || ($order_total == 0))
						{
							$order_total = $order["grand_total"];
						}
					}
				}
				$tel = $shippingAddress->getTelephone();
				$shipping_postcode = $shippingAddress->getPostcode();
				$shipping_zone = $shippingAddress->getRegion();
				$shipping_city = $shippingAddress->getCity();
				$country_id = $shippingAddress->getCountry_id();
				$shipping_address_1 = $shippingAddress->getStreetFull();		
				$shipping_customer_name = $shippingAddress->getFirstname()." ".$shippingAddress->getLastname();
				if($customerIsGuest)
				{
					//匿名下单时 customer_name = Guest，所以这里调整成收货人
					$customer_name = $shipping_customer_name;
				}
				$curCountry = $country->loadByCode($country_id);
				$shipping_country = $curCountry->getName();
				$order_state = $order["state"];
				foreach($order->getAllVisibleItems() as $item)
				{
					$product_id = $item["product_id"];
					$product->setStoreId($store_id);
					$curProduct = $product->load($product_id);
					
					$product_sku = $curProduct->getSku();
					$product_name = $item["name"];
					$product_model = $curProduct["model"];
					//产品图片
					$product_image_urls = array();
					$product_image_url = $curProduct["image"];
					if(strlen($product_image_url) > 0)
					{		
					    if(($product_image_url <> "no_selection") && ($product_image_url <> "object"))
						{
							$product_image_url = str_replace($media_product_base_url, "", $product_image_url);
							array_push($product_image_urls, $product_image_url);
						}
					}
					$mediaGalleryImages = $curProduct->getMediaGalleryImages();
					if($mediaGalleryImages)
					{
						foreach($mediaGalleryImages as $mediaGalleryImage)
						{
							try
							{
								$product_image_url = str_replace($media_product_base_url, "", $mediaGalleryImage["url"]);
								array_push($product_image_urls, $product_image_url);							
							}
							catch(Exception $e)
							{
							}
						}
					}
					$product_image_urls = array_unique($product_image_urls);
					$product_price = $item["price"];
					$product_qty = $item["qty_ordered"];
					$product_total = $item["base_row_total"];
					//合计产品属性信息
					$product_size = "";
					$productOptions = $item->getProductOptions();
					if($productOptions)
					{
						if(isset($productOptions['attributes_info']))
						{
							foreach($productOptions['attributes_info'] as $itemOption)
							{
								$label = $itemOption["label"];
								$value = $itemOption["value"];
								if($product_size == "")
									$product_size = $label." : ".$value."\r\n  ";
								else
									$product_size .= $label." : ".$value."\r\n  ";
							}
						}
						if(isset($productOptions['options']))
						{
							foreach($productOptions['options'] as $itemOption)
							{
								$label = $itemOption["label"];
								$value = $itemOption["value"];
								if($product_size == "")
									$product_size = $label." : ".$value."\r\n  ";
								else
									$product_size .= $label." : ".$value."\r\n  ";
							}
						}
					}
 					$select[] = array("product_name"=>$product_name,
						 "product_sku"=>$product_sku,
						 "product_model"=>$product_model,
						 "product_size"=>$product_size,
						 "quantity"=>$product_qty,
						 "price"=>$product_price,
						 "total"=>$product_total,
						 "product_image_urls"=>$product_image_urls,
						 "shipping_order_id"=>$shipping_order_id,
						 "customer_name"=>$customer_name,
						 "email"=>$email,
						 "tel"=>$tel,
						 "fax"=>"",
						 "shipping_customer_name"=>$shipping_customer_name,
						 "shipping_company"=>"",
						 "shipping_address_1"=>$shipping_address_1,
						 "shipping_address_2"=>"",
						 "shipping_city"=>$shipping_city,
						 "shipping_postcode"=>$shipping_postcode,
						 "shipping_country"=>$shipping_country,
						 "shipping_zone"=>$shipping_zone,
						 "shipping_method"=>$shipping_method,
						 "payment_method"=>$payment_method,
						 "currency_code"=>$currency_code,
						 "shipping_to_rate"=>$shipping_to_rate,
						 "insurance_premium"=>0,
						 "procedure_fee"=>0,
						 "sub_total"=>$sub_total,		
						 "order_total"=>$order_total,
						 "shipping_order_date"=>$shipping_order_date,	 
						 "ip"=>$ip,		
						 "order_status"=>$order_state,						 
						 "HasPay"=>0); 
					 
					$curProduct->reset();
				}
				$order->reset();
			}

			if($select == null)
				echo "";
			else
				echo json_encode($select); 	

		}
		else if($requestKind == "4")
		{
			if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_GET['webSystemKind']))
			{
				//判断临时文件存放路径是否包含用户上传的文件
				if(is_uploaded_file($_FILES["file"]["tmp_name"]))
				{
					$webSystemKind = $_GET['webSystemKind'];
					$subFolderPath = $_GET['subFolderPath'];
					$uploadDir = '';
					switch($webSystemKind)
					{
					case 0://Magento
						$uploadDir = './media/catalog/product/';
						break;
					case 1://ZenCart
						$uploadDir = './images/';
						break;
					case 2://OpenCart
						$uploadDir = './image/';
						break;
					case 3://EcShop
						$uploadDir = './images/';
						break;
					}
					if($uploadDir <> '')
					{
						$fileTypes  = array('jpg', 'jpeg', 'png', 'gif', 'bmp');
						$maxSize    = 1 * 1024 * 1024; //1M
						//为了更高效，将信息存放在变量中
						$upfile = $_FILES["file"];//用一个数组类型的字符串存放上传文件的信息
						$name = $upfile["name"];//便于以后转移文件时命名
						$type = $upfile["type"];//上传文件的类型
						$size = $upfile["size"];//上传文件的大小
						$tmp_file_name = $upfile["tmp_name"];//用户上传文件的临时名称
						$error = $upfile["error"];//上传过程中的错误信息
						$myFileType = substr($upfile['name'], strrpos($upfile['name'], ".") + 1);
						if ($size <= $maxSize) 
						{
							if (in_array($myFileType, $fileTypes)) 
							{
								//调用move_uploaded_file（）函数，进行文件转移
								$toFilePath = $uploadDir.$subFolderPath;
								if(!(file_exists($toFilePath)))
								{
									//create the folder
									mkdir($toFilePath, 0777);
									//give permission to the folder
									@chmod($toFilePath, 0777);//赋予权限
								}
								else
								{
									@chmod($toFilePath, 0777);//赋予权限
								}
								@is_dir($toFilePath) or mkdir($toFilePath, 0777);
								$toFullFileName = $toFilePath.'/'.$name;
								if (@move_uploaded_file($tmp_file_name, $toFullFileName)) 
								{
									//查看是否存在产品，如果没有则添加产品信息，否则都增加产品图片信息
								
								
									$result = 1;
									$resultMsg = '文件上传成功';
								}
								else
								{
									$resultMsg = '文件转移失败';
								}
							}
							else
							{
								$resultMsg = '不支持的文件类型';
							}
						}
						else
						{
							$resultMsg = '文件太大';
						}
					}
					else
					{
						$resultMsg = '未知系统';
					}
				}
				else
				{
					$resultMsg = '临时目录中不存在该上传的文件';
				}
			}
			else
			{
				$resultMsg = '未知请求';
			}
			echo $result.'='.$resultMsg;
		}
	}
}
catch(Exception $e)
{
	echo "0=".$e->getMessage();
}
?>