Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML form file upload [duplicate]

Tags:

html

php

I'm having difficulty trying to save a file uploaded from a form, I've checked the tutorial found on the w3schools website but I keep getting an undefined index error:

Notice: Undefined index: userpic in 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>

and the code I'm using to try and save it to a folder called 'images':

move_uploaded_file($_FILES["userpic"]["tmp_name"],"images/".$_FILES["userpic"]["name"]);
like image 629
AuthenticReplica Avatar asked Mar 14 '13 15:03

AuthenticReplica


1 Answers

Use enctype="multipart/form-data" in you form.

<form action="confirm.php" enctype="multipart/form-data" method="post">
like image 84
Sibiraj PR Avatar answered Nov 05 '22 02:11

Sibiraj PR