如题所示,在提交表单时出现Notice: Undefined index: myfile in D:\WWW\course\admin\alluser.php on line 10的错误,
表单的内容传不过来,出现空值。
<html>
<form action="alluser.php" role="form1" class="form-horizontal"
method="post" name="upform">
<div class="col-md-12">
<h4>文件导入用户</h4>
</div>
<div class="col-md-12">
<label for="fileselect" class="col-md-2 control-label">请选择文件</label>
<div class="col-md-4">
<input type="file" id="fileselect" name="myfile">
</div>
<div class="col-md-2 alert-danger" id="upp">请选择文件</div>
<div class="col-md-2">
<p>注:文件格式为Excel,数据为用户id+用户名,初始密码为123456</p>
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-info" id="insert">录入</button>
</div>
</div>
</form>
php代码:
<?php
include_once ("../login/config/config.php");
if(!empty($_FILES["myfile"])){
$file = $_FILES["myfile"];
}
if ($_FILES["myfile"]["error"] > 0)
{
echo "Error: " . $_FILES["myfile"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["myfile"]["name"] . "<br />";
echo "Type: " . $_FILES["myfile"]["type"] . "<br />";
echo "Size: " . ($_FILES["myfile"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["myfile"]["tmp_name"];
}
$filename=$_FILES['myfile']['name'];
$filepath=$_FILES['myfile']['tmp_name'];
//$filepath="";
echo "<script type='text/javascript'>
alert('".$filepath."');
</script>";
?>
------解决方案--------------------
表单如果要上传文件需要加上enctype="multipart/form-data"
<form action="alluser.php" role="form1" class="form-horizontal" method="post" name="upform" enctype="multipart/form-data">
------解决方案--------------------
楼上正解提交文件需要加:enctype="multipart/form-data"