I’ve got kind of an annoying problem. When I submit the following code using method=”post” and looking for the $_POST variable, the code doesn’t recognize it. When I switch to method=”get” and look for the $_GET variable it works fine. I would prefer not to use Get. Any suggestions? My final code will contain other inputs as well, however, I want the file input to be optional. So I need to process the code only if the file input is actually sent. Thanks for your help!
//form.html.php
<form action="index.php" method="post" enctype="multipart/form-data">
<label id="upload">Select file to upload:
<input type="file" id="upload" name="foobar" /></label>
<input type="submit" value="Submit" />
</form>
//index.php
if(isset($_POST['foobar']))
{
//some code
}
However, this works fine
//form.html.php
<form action="index.php" method="get" enctype="multipart/form-data">
<label id="upload">Select file to upload:
<input type="file" id="upload" name="foobar" /></label>
<input type="submit" value="Submit" />
</form>
//index.php
if(isset($_GET['foobar']))
{
//some code
}
To get file, please use
$_FILES, and you must usepostmethod.