PHP POST method not posting “type=file” variable
I am updating some old PHP to move away from global variables and use $_GET, $_POST, etc (among plenty of other things). I bumped into an issue where my image upload form was not passing type=file variables to $_POST. The form looks like so:
<div class="block">
<label>upload photo</label>
<input type="file" name="userpic">
</div>
I couldn’t get the value via the following:
$userpic = $_POST['userpic'];
W3Schools to the rescue.
By using the global PHP $_FILES array you can upload files from a client computer to the remote server. The first parameter is the form’s input name and the second index can be either “name”, “type”, “size”, “tmp_name” or “error”.
The answer is therefore:
$userpic = $_FILES['userpic']['name'];
Hope this helps someone!
Leave a comment