【问题标题】:HTML form file upload [duplicate]HTML表单文件上传[重复]
【发布时间】:2013-03-03 00:48:48
【问题描述】:

我在尝试保存从表单上传的文件时遇到困难,我查看了 w3schools 网站上的教程,但一直收到未定义的索引错误:

注意:未定义索引:C:\wamp\www\HW4\confirm.php 中的用户图片

<form action="confirm.php" method="post">
<div>
<fieldset>
<legend>New User Signup: </legend>
<label> <strong>Name:</strong> <input type="text" name="name" size="16" /></label><br/>
<label> <strong>Gender:</strong> <input type="radio" name="gender" value="M"/> Male
<input type="radio" name="gender" value="F" /> Female
</label><br/>
<label> <strong>Age:</strong> <input type="text" name="age" size="6" maxlength="2" />                         </label>    <br/>
<label> <strong>Personality type:</strong> <input type="text" name="personality"     size="6" maxlength="4" />(<a href="http://www.humanmetrics.com/cgi-win/JType2.asp">Don't     know your type?</a>)</label>
<br/>
    <label> <strong>Favorite OS:</strong> <select name="favos">
    <option selected="selected">Windows</option>
    <option>Mac OS X</option>
    <option>Linux</option></select>
</label><br/>
<label> <strong>Seeking age:</strong> 
<input type="text" name="minage" size="6" maxlength="2" placeholder="min" /> to 
<input type="text" name="maxage" size="6" maxlength="2" placeholder="max"/>
</label><br/>
<label><strong>Photo:</strong><input type="file" name="userpic" id="userpic" /></label>
<input type="submit" value="Sign Up" />
</fieldset>
</div>
</form>

以及我用来尝试将其保存到名为“images”的文件夹的代码:

move_uploaded_file($_FILES["userpic"]["tmp_name"],"images/".$_FILES["userpic"]["name"]);

【问题讨论】:

标签: php html


【解决方案1】:

在你的表单中使用enctype="multipart/form-data"

<form action="confirm.php" enctype="multipart/form-data" method="post">

【讨论】:

    猜你喜欢
    • 2011-12-04
    • 2016-05-01
    • 2010-12-05
    • 2012-01-28
    • 1970-01-01
    • 2014-06-06
    • 2011-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多