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"]);
Use enctype="multipart/form-data"
in you form.
<form action="confirm.php" enctype="multipart/form-data" method="post">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With