先貼一個最簡單的文件上傳模型
<html>
<form method="post" action='index.php' enctype="multipart/form-data">
<input type="file" name="file" id="file">
<input type="submit" value="提交">
</form>
</html>
<?php
if (isset($_FILES['file'])) {
$dst = './test_'.$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $dst);
}
不對字符編碼。
在使用包含文件上傳控件的表單時,必須使用該值。
text/plain 空格轉換為 "+" 加號,但不對特殊字符編碼。
enctype屬性的作用是設置表單傳輸的編碼。通過抓包可以看到由enctype設置的MIME編碼:
