这个是我的提交页面<!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" />
<title>添加商品</title>
<style type="text/css">
.style1{color:#FFFFFF}
td{font-size:12px;color:#006699}
</style></head><body>
<?
$connect = mysql_connect("localhost","root","sql");
mysql_select_db("db_shop");
if (!$connect)
{
echo("连接失败!");
}
?>
<script language="javascript">
function checkinputform(form){
var ls = form.gname.value;
if(ls =='')
{
alert("產品不能為空!");
form.gname.select();
return false;
}
if(form.etprice.value == '')
{
alert("市场价不能为空!");
form.etprice.select();
return false;
}
if(form.meberprice.value == '')
{
alert("会员价不能为空!");
form.meberprice.select();
return false;
}
if(form.meberprice.value!=form.meberprice.value.match("[0-9]*[1-9][0-9]*$")){
alert("this is reg");
}
}
function onloadfile()
{
var name_app = document.getElementById("uploadfile").value();
var ar = name_app.split("\\");
/*
var name = ar[ar.length-1];
alert(name);*/
alert(name_app);
}
</script> <form action="savegoods.php" method="post" enctype="multipart/form-data"onsubmit="return checkinputform(this)"> <table width = "760" align="center" cellpadding="10" cellspacing="1" border="1" >
<tr height="20" >
<td align="center" bgcolor="#FFCF60" class="style1" colspan="2" border="0" >
添加商品
</td> <tr>
<td width="60" height="25" size="12" >商品名称:</td>
<td width="730"><input type = "text" name = "gname"></td>
</tr>
<tr>
<td width="60" height="25" size="12" >上市时间:</td>
<td height="25">
<select name = "year">
<?
for($i=1995;$i<=2050;$i++)
{
?>
<option><? echo("$i") ;?> </option>
<? } ?>
</select> 年
<select name = "month">
<?
for($i=1;$i<=12;$i++)
{
?>
<option><? echo("$i") ;?> </option>
<? } ?>
</select> 月
<select name ="date">
<? for($i= 1; $i<=31;$i++){?>
<option> <? echo("$i"); ?></option>
<? }?>
</select> 日
</td>
</tr>
<tr>
<td width="60" height="25" size="12" align="right">价格:</td>
<td height="25">市场价:<input type="text" name="etprice" size="3"> 元 会员价:<input type="text" name="memberprice" size="3"> 元</td>
</tr>
<td width="60" height="25" size="12" align="right" >商品类型:</td>
<td>
<?
$sql=mysql_query("select * from tb_type order by id desc",$connect);
$info=mysql_fetch_array($sql);
?>
<select name = "typename">
<? do {?>
<option value = <? echo($info[typename]);?>> <? echo($info[typename]);?></option>
<? } while($info=mysql_fetch_array($sql))?>
</select>
</td>
</tr>
<tr>
<td width="60" height="25" size=12 align="right">商品等级:</td>
<td>
<select name="cate"> <option value="精品">精品</option>
<option value="一般">一般</option>
<option value="二手">二手</option>
<option value="淘汰">淘汰</option>
</select>
</td>
</tr>
<tr>
<td align="right" > 商品品牌:</td>
<td> <input type ="text" name="brand"> </td>
</tr>
<td align="right" > 商品型号:</td>
<td> <input type ="text" name="goodstype"> </td>
</tr>
<tr>
<td align="right">是否推荐:</td>
<td><select name ="recomend">
<option value='Y' >是</option>
<option value='N' >否</option>
</select></td>
</tr>
<tr>
<td align="right">商品数量: </td>
<td><input type="text" name ="qaulity"></td>
</tr>
<tr>
<td align="right">上传文件:</td>
<td><input type ="file" name="uploadfile" id = 'uploadfile' size="30" onchange="onloadfile()"><input type ="hidden" name="MAX_FILE_SIZE" value="200000"></td>
</tr>
<tr>
<td height="80" align="right">商品简介:</td>
<td><textarea name="resum" cols="50" rows="5" ></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="submit" name="submit" value="提交">   <input type="reset" id="reset" name="reset" value="重置"></td>
</tr>
</table>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加商品</title>
<style type="text/css">
.style1{color:#FFFFFF}
td{font-size:12px;color:#006699}
</style></head><body>
<?
$connect = mysql_connect("localhost","root","sql");
mysql_select_db("db_shop");
if (!$connect)
{
echo("连接失败!");
}
?>
<script language="javascript">
function checkinputform(form){
var ls = form.gname.value;
if(ls =='')
{
alert("產品不能為空!");
form.gname.select();
return false;
}
if(form.etprice.value == '')
{
alert("市场价不能为空!");
form.etprice.select();
return false;
}
if(form.meberprice.value == '')
{
alert("会员价不能为空!");
form.meberprice.select();
return false;
}
if(form.meberprice.value!=form.meberprice.value.match("[0-9]*[1-9][0-9]*$")){
alert("this is reg");
}
}
function onloadfile()
{
var name_app = document.getElementById("uploadfile").value();
var ar = name_app.split("\\");
/*
var name = ar[ar.length-1];
alert(name);*/
alert(name_app);
}
</script> <form action="savegoods.php" method="post" enctype="multipart/form-data"onsubmit="return checkinputform(this)"> <table width = "760" align="center" cellpadding="10" cellspacing="1" border="1" >
<tr height="20" >
<td align="center" bgcolor="#FFCF60" class="style1" colspan="2" border="0" >
添加商品
</td> <tr>
<td width="60" height="25" size="12" >商品名称:</td>
<td width="730"><input type = "text" name = "gname"></td>
</tr>
<tr>
<td width="60" height="25" size="12" >上市时间:</td>
<td height="25">
<select name = "year">
<?
for($i=1995;$i<=2050;$i++)
{
?>
<option><? echo("$i") ;?> </option>
<? } ?>
</select> 年
<select name = "month">
<?
for($i=1;$i<=12;$i++)
{
?>
<option><? echo("$i") ;?> </option>
<? } ?>
</select> 月
<select name ="date">
<? for($i= 1; $i<=31;$i++){?>
<option> <? echo("$i"); ?></option>
<? }?>
</select> 日
</td>
</tr>
<tr>
<td width="60" height="25" size="12" align="right">价格:</td>
<td height="25">市场价:<input type="text" name="etprice" size="3"> 元 会员价:<input type="text" name="memberprice" size="3"> 元</td>
</tr>
<td width="60" height="25" size="12" align="right" >商品类型:</td>
<td>
<?
$sql=mysql_query("select * from tb_type order by id desc",$connect);
$info=mysql_fetch_array($sql);
?>
<select name = "typename">
<? do {?>
<option value = <? echo($info[typename]);?>> <? echo($info[typename]);?></option>
<? } while($info=mysql_fetch_array($sql))?>
</select>
</td>
</tr>
<tr>
<td width="60" height="25" size=12 align="right">商品等级:</td>
<td>
<select name="cate"> <option value="精品">精品</option>
<option value="一般">一般</option>
<option value="二手">二手</option>
<option value="淘汰">淘汰</option>
</select>
</td>
</tr>
<tr>
<td align="right" > 商品品牌:</td>
<td> <input type ="text" name="brand"> </td>
</tr>
<td align="right" > 商品型号:</td>
<td> <input type ="text" name="goodstype"> </td>
</tr>
<tr>
<td align="right">是否推荐:</td>
<td><select name ="recomend">
<option value='Y' >是</option>
<option value='N' >否</option>
</select></td>
</tr>
<tr>
<td align="right">商品数量: </td>
<td><input type="text" name ="qaulity"></td>
</tr>
<tr>
<td align="right">上传文件:</td>
<td><input type ="file" name="uploadfile" id = 'uploadfile' size="30" onchange="onloadfile()"><input type ="hidden" name="MAX_FILE_SIZE" value="200000"></td>
</tr>
<tr>
<td height="80" align="right">商品简介:</td>
<td><textarea name="resum" cols="50" rows="5" ></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="submit" name="submit" value="提交">   <input type="reset" id="reset" name="reset" value="重置"></td>
</tr>
</table>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?
/*if(!is_numeric($_POST[etprice]))
{
echo("<script> alert('市場價一定要是數字!' ); history.back();</script>");
}
if(!is_numeric($_POST[memberprice]))
{
echo("<script> alert('會員價只能是數字!');history.back();</script>");
}
$gname = $_POST[gname];*/
$year = $_POST[year];
$month = $_POST[month];
$date = $_POST[date];
$etprice = $_POST[etprice];
$memberprice = $_POST[memberprice];
$gtype = $_POST[typename];
$cate = $_POST[cate];
$brand = $_POST[brand];
$goodstype = $_POST[goodstype];
$recomend = $_POST[recomend];
$resum = $_POST[resum];
$uploadfile = $_POST[uploadfile];
//echo($_FILES['uploadfile']['name'] ); function getloadname($exname)
{
$dir = "uplaodfile/";
$i = 1 ;
if (!is_dir($dir) )
{
mkdir($dir,0777);
}
while (true)
{
if(!is_file($dir.$i.$name))
{
return $i.".".$exname;
break;
}
$i++;
}
}
$exname = strtolower(substr($_FILES['uploadfile']['name'],strpos($_FILES['uploadfile']['name'],'.') + 1));
$filename = getloadname($exname);
echo($_FILES['uploadfile']['name']);
echo($filename);
echo($_POST['uploadfile']['tmp_name']);
if(move_uploaded_file($_POST['uploadfile']['tmp_name'],$filename))
{
echo("This is successful!");
}
else
{
echo("This is false!");
}
?>
</body>
</html>
————————————————————————————————————————————
其中 echo($_FILES['uploadfile']['name']); 这个值可以显示出来,但是这个
echo($_POST['uploadfile']['tmp_name']);显示不出来,导致move_uploaded_file($_POST['uploadfile']['tmp_name'],$filename)执行返回false 请大侠指教!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?
/*if(!is_numeric($_POST[etprice]))
{
echo("<script> alert('市場價一定要是數字!' ); history.back();</script>");
}
if(!is_numeric($_POST[memberprice]))
{
echo("<script> alert('會員價只能是數字!');history.back();</script>");
}
$gname = $_POST[gname];*/
$year = $_POST[year];
$month = $_POST[month];
$date = $_POST[date];
$etprice = $_POST[etprice];
$memberprice = $_POST[memberprice];
$gtype = $_POST[typename];
$cate = $_POST[cate];
$brand = $_POST[brand];
$goodstype = $_POST[goodstype];
$recomend = $_POST[recomend];
$resum = $_POST[resum];
$uploadfile = $_POST[uploadfile];
//echo($_FILES['uploadfile']['name'] ); function getloadname($exname)
{
$dir = "uplaodfile/";
$i = 1 ;
if (!is_dir($dir) )
{
mkdir($dir,0777);
}
while (true)
{
if(!is_file($dir.$i.$name))
{
return $dir.$i.".".$exname;
break;
}
$i++;
}
}
$exname = strtolower(substr($_FILES['uploadfile']['name'],strpos($_FILES['uploadfile']['name'],'.') + 1));
$filename = getloadname($exname);
$_lb = move_uploaded_file($_FILES['uploadfile']['temp_name'],$filename);
if($_lb == null)
{
echo("This is null");}?>
</body>
</html>------------------------------------------move_uploaded_file函数返回null值,
$_FILES这个超全局变量专门用来处理文件上传的