我在尝试保存从表单上传的文件时遇到了困难,我已经检查了w3schools网站上发现的教程,但我一直收到一个未定义的索引错误:
注意:未定义索引:C:\ wamp \ www \ HW4 \ confirm.php中的userpic
<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"]);
答案 0 :(得分:5)
在表单中使用enctype="multipart/form-data"
。
<form action="confirm.php" enctype="multipart/form-data" method="post">