Reputation: 2464
Last time I asked a question here I messed up but I think I got it now. Please let me know if I can ask better :D
I am using an HTML form with PHP and am trying to get a file name. I am using Bootstrap for the formatting, my Form looks like this:
<form role="form" class="form-horizontal" action=<?php echo $_SERVER['PHP_SELF']; ?> method="post">
<div class="form-group">
<label for="file" class="col-sm-3 control-label">Picture</label>
<div class="col-sm-9">
<input style="margin-top: 7.5px;" type="file" name="file" id="file" required>
</div>
</div>
<button type="submit" class="btn btn-success btn-lg btn-block">Submit</button>
</form>
And then directly after that code I have this:
<?php echo "File: " . $_FILES["file"]["name"]; ?>
Which upon first visiting the page outputs just (which is correct):
File:
However after I select a file and hit submit the php code at the end still only outputs "File: "
Anyone know why this is happening?
Thank you very much
Upvotes: 1
Views: 3976
Reputation: 219804
You're missing your enctype="multipart/form-data"
attribute in your <form>
tag. Without it the file will not upload.
<form enctype="multipart/form-data" role="form"
class="form-horizontal" action=<?php echo $_SERVER['PHP_SELF']; ?> method="post">
Upvotes: 9