<?
require_once("../inc/conn.php");
require_once("../inc/function.php");
//******************MAIN*******************
$goodsName = $_POST["goodsName"];
$goodsCode = $_POST["goodsCode"];
$goodsClassid = $_POST["goodsClassid"];
$goodsMsg = $_POST["goodsMsg"];
$smallImg = "small_img".rand(0,99999).date("Y-m-d-h-m-s",time()); //缩略图名称
$toW = 100; // 生成图片的宽度
$toH = 100; // 生成图片的高度
$filePath = "../UserFileSpace/goodsImage/";
if ( isset($_POST["Submit"]) )
{
$fileName = time().$_FILES['goodsPic']['name'];
$upfile=$filePath.$fileName;
if(is_uploaded_file($_FILES['goodsPic']['tmp_name']))
{
if(!move_uploaded_file($_FILES['goodsPic']['tmp_name'],$upfile))
{
echo "文件上传失败";
exit;
}
else
{
$CreateImage = $smallImg.checkExt($_FILES['goodsPic']['type']);
ImageResize($upfile,$toW,$toH,$filePath.$CreateImage);
$Insertgoods = mysql_query( "INSERT INTO `goodsinfo` ( `gdcode`, `gdtitle`, `gdmsg`, `smallimg`, `bigimg`, `gdclassid`, `pt`,`uname`) VALUES ( '".$goodsCode."', '".$goodsName."', '".$goodsMsg."', '".$CreateImage."', '".$fileName."', 6, now(),'skyadmin' )",dbconn());
echo "文件上传成功!";
redirect( "?");
}
}
}
function checkExt($fileExt)
{
if ( strpos($fileExt , "gif") )
{
return ".gif";
}
else
{
if ( strpos($fileExt , "jpeg") )
{
return ".jpg";
}
else
{
if ( strpos($fileExt , "png") )
{
return ".png";
}
else
{
return;
exit();
}
}
}
}
function ImageResize($srcFile,$toW,$toH,$toFile="")
{
if($toFile== ""){ $toFile = $srcFile; }
$info = "";
$data = GetImageSize($srcFile,$info);
switch ($data[2])
{
case 1:
if(!function_exists( "imagecreatefromgif")){
echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!<a href='javascript:go(-1);'>返回</a>";
exit();
}
$im = ImageCreateFromGIF($srcFile);
break;
case 2:
if(!function_exists( "imagecreatefromjpeg")){
echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!<a href='javascript:go(-1);'>返回</a>";
exit();
}
$im = ImageCreateFromJpeg($srcFile);
break;
case 3:
$im = ImageCreateFromPNG($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH=ImageSY($im);
$toWH=$toW/$toH;
$srcWH=$srcW/$srcH;
if($toWH <=$srcWH){
$ftoW=$toW;
$ftoH=$ftoW*($srcH/$srcW);
}
else{
$ftoH=$toH;
$ftoW=$ftoH*($srcW/$srcH);
}
if($srcW >$toW||$srcH>$toH)
{
if(function_exists( "imagecreatetruecolor")){
@$ni = ImageCreateTrueColor($ftoW,$ftoH);
if($ni) ImageCopyResampled($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);
else{
$ni=ImageCreate($ftoW,$ftoH);
ImageCopyResized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);
}
}else{
$ni=ImageCreate($ftoW,$ftoH);
ImageCopyResized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);
}
if(function_exists('imagejpeg')) ImageJpeg($ni,$toFile);
else ImagePNG($ni,$toFile);
ImageDestroy($ni);
}
ImageDestroy($im);
}
?>
<div id="main">
<p> </p>
<form name="form1" method="post" enctype="multipart/form-data">
<input type=hidden name="MAX_FILE_SIZE" value="30000">
<p>商品名称:
<input name="goodsName" type="text" id="goodsName">
</p>
<p>商品编号:
<input name="goodsCode" type="text" id="goodsCode">
</p>
<p> 所属类别:
<input name="goodsClassid" type="text" id="goodsClassid">
</p>
<p>产品图片:
<input name="goodsPic" type="file" id="goodsPic">
</p>
<p> 内容:
<textarea name="goodsMsg" cols="50" rows="10" id="goodsMsg"></textarea>
</p>
<p>
<input type="submit" name="Submit" value="提 交">
</p>
</form>
<p> </p>
</div>