本文介绍了通过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.

来自php.net的示例1 :

<!-- 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>

这篇关于通过html表单上传文件.在PHP中,$ _ FILES为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 05:53