通过html表单上传文件.在PHP中,$ _ FILES为空
问题描述:
所以我有这段代码:
<form name="form" action="./" method="post">
<input type="file" name="newfile" id="newfile" />
</form>
当我在操作页面上运行此php脚本时,什么也没发生
When I run this php script on the action page, nothing happens
echo "$_FILES['newfile']['name'];
print_r($_FILES);
就像$_FILES
变量为空.有什么办法可以解决这个问题?
It is like the $_FILES
variable is empty. Is there any way to fix this?
答
您需要在表单上设置enctype="multipart/form-data"
属性.
You need to set the enctype="multipart/form-data"
attribute on your form.
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="__URL__" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>