上传图片的时候表单有enctype="multipart/form-data"方式 但是这个种方式就获取不到text文本的值,求指点
a.html
<form action="b.php" method="post" enctype="multipart/form-data" id="ces">
上传:<input type="file" name="filename" />
<input type="submit" value="上传" name="btn"/>
<input type="reset" value="取消" name="btn1"/>
<input name="" id="test" type="text" />
</form>
test的值获取不到- -
b.php
<?php
$path="../user_pic/2/"; //上传路径
$c=$_POST['test'];
echo $c;
//echo $_FILES["filename"]["type"];
$file2="a.jpg";
if(!file_exists($path))
{
//检查是否有该文件夹,如果没有就创建,并给予最高权限
mkdir("$path", 0700);
}//END IF
//允许上传的文件格式
//if(file_exists($path.$file2))
//{
// $a=$path.$file2;
// if(unlink("$a"))
// {
// echo "aaa";
// }
//
//}
//$tp = array("image/gif","image/pjpeg","image/png","image/jpg");
////检查上传文件是否在允许上传的类型
//if(!in_array($_FILES["filename"]["type"],$tp))
//{
//echo "格式不对";
//exit;
//}//END IF
if($_FILES["filename"]["name"])
{
$file1=$_FILES["filename"]["name"];
echo "aaa";
//$file2 = $path.time().$file1;
//修改上传完毕的文件名
}//END IF
$result=move_uploaded_file($_FILES["filename"]["tmp_name"],$path.$file2);
//特别注意这里传递给move_uploaded_file的第一个参数为上传到服务器上的临时文件
if($result)
{
//echo "上传成功!".$file2;
echo "<script language='javascript'>";
echo "alert(\"上传成功!\");";
}//END IF
?>
a.html
<form action="b.php" method="post" enctype="multipart/form-data" id="ces">
上传:<input type="file" name="filename" />
<input type="submit" value="上传" name="btn"/>
<input type="reset" value="取消" name="btn1"/>
<input name="" id="test" type="text" />
</form>
test的值获取不到- -
b.php
<?php
$path="../user_pic/2/"; //上传路径
$c=$_POST['test'];
echo $c;
//echo $_FILES["filename"]["type"];
$file2="a.jpg";
if(!file_exists($path))
{
//检查是否有该文件夹,如果没有就创建,并给予最高权限
mkdir("$path", 0700);
}//END IF
//允许上传的文件格式
//if(file_exists($path.$file2))
//{
// $a=$path.$file2;
// if(unlink("$a"))
// {
// echo "aaa";
// }
//
//}
//$tp = array("image/gif","image/pjpeg","image/png","image/jpg");
////检查上传文件是否在允许上传的类型
//if(!in_array($_FILES["filename"]["type"],$tp))
//{
//echo "格式不对";
//exit;
//}//END IF
if($_FILES["filename"]["name"])
{
$file1=$_FILES["filename"]["name"];
echo "aaa";
//$file2 = $path.time().$file1;
//修改上传完毕的文件名
}//END IF
$result=move_uploaded_file($_FILES["filename"]["tmp_name"],$path.$file2);
//特别注意这里传递给move_uploaded_file的第一个参数为上传到服务器上的临时文件
if($result)
{
//echo "上传成功!".$file2;
echo "<script language='javascript'>";
echo "alert(\"上传成功!\");";
}//END IF
?>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货