我正在尝试将文件上传到服务器上。每当我提交时,php全局数组$ _FILES都是空的。我的文件继续进入$ _POST。
<form action="process.php" method="POST">
<div class="form-group"></div>
<div class="form-group">
<input type="file" name="uploaded_file">
</div>
<div class="form-group">
<button type="submit" class="btn btn-danger">Upload</button>
</div>
</form>
process.php
<?php
var_dump($_FILES['uploaded_file']);
var_dump($_POST['uploaded_file']);
答案 0 :(得分:5)
你应该像这样使用enctype="multipart/form-data"
<form action="process.php" method="POST" enctype="multipart/form-data">
<div class="form-group"></div>
<div class="form-group">
<input type="file" name="uploaded_file">
</div>
<div class="form-group">
<button type="submit" class="btn btn-danger">Upload</button>
</div>
</form>
答案 1 :(得分:4)
将enctype="multipart/form-data"
添加到html中
像:
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>