好的,所以我正在尝试构建一个系统,管理员可以为公司中其他部门的人员上载文件。所以我当时正在处理php文件上传脚本,但是我一直收到此错误
注意:未定义索引:filetoUpload
这是我的代码。
Index.html
<form class="form-group" method="POST" action="upload.php">
<select class="form-control col-sm-6" name="department">
<option>Department</option>
<option>HR</option>
<option>Engineering</option>
<option>Finance</option>
<option>HR Forms</option>
<option>IT</option>
<option>Learning Center Other</option>
<option>Learning Center Technical</option>
<option>Marketing</option>
<option>Operations</option>
<option>Processe<s/option>
<option>Other</option>
</select><br>
<input type="file" name="fileToUpload" value="Choose File" id="fileToUpload" class="btn btn-info"><br>
<input type="submit" name="btn" class="btn btn-primary" value="Upload" style="margin-top: 10px;">
</form>
upload.php
<?php
$department = $_POST['department'];
$file = $_FILES['fileToUpload']['name'];
echo $department . $file;
?>
答案 0 :(得分:2)
如果表单包含文件上传,请使用multipart/form-data
。
enctype属性指定将表单数据提交到服务器时应如何编码。
所以您的表格应如下所示:
<form class="form-group" method="POST" action="upload.php" enctype="multipart/form-data">
<select class="form-control col-sm-6" name="department">
<option>Department</option>
<option>HR</option>
<option>Engineering</option>
<option>Finance</option>
<option>HR Forms</option>
<option>IT</option>
<option>Learning Center Other</option>
<option>Learning Center Technical</option>
<option>Marketing</option>
<option>Operations</option>
<option>Processe<s/option>
<option>Other</option>
</select><br>
<input type="file" name="fileToUpload" value="Choose File" id="fileToUpload" class="btn btn-info"><br>
<input type="submit" name="btn" class="btn btn-primary" value="Upload" style="margin-top: 10px;">
</form>