//photoform.php
<html>
<body>
<form action="upload.php" name="phsub" method="post" enctype="multipart/form-data">
<?php
session_start();
$op=$_POST["opcnt"];
if ($op!="Select")
{
echo "<fieldset>";
echo "<legend> Open Category </legend>";
for ($i=1;$i<=$op;$i++)
{
echo "<input name='ofile$i' id='ofile$i' type='file'/>";
echo"<br>";
}
echo "</fieldset>";
}
?>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
upload.php
<?php
$empty = $post = array();
foreach ($_POST as $varname => $varvalue) {
if(empty($varvalue)) {
$empty[$varname] = $varvalue;
}
else {
$post[$varname] = $varvalue;
}
}
print "<pre>";
if (empty($empty)) {
print "None of the POSTed values are empty, posted:
";
var_dump($post);
}
else {
print "We have " . count($empty) . " empty values
";
print "Posted:
";
var_dump($post);
print "Empty:
";
var_dump($empty);
exit;
}
?>
Question : When I am listing all $post values, I am only getting the "submit" button which is static. I can see all generated file upload controls based on the condition. But unable to get the control in upload.php file. Can you please suggest if there is anything wrong in the code. I am new to PHP. Thanks in advance for your inputs.
Thanks - Abhik Banerjee
In photoform.php
output the $_POST
variable to confirm that $_POST['opcnt']
is not select
.
Also, if you can, add the actual output html from photoform.php
as it is likely to missing fields and/or names of fields.
Also,
//upload.php
<?php
var_dump($_POST);
?>
To access form POST
variables use $_POST
.
// Update
As your form
is submitting input
with type as file
, these are considered as a special case. The values will be mapped to the $_FILES
variable.
See the php docs on php.net for more clarification.
You can get the file details from $_FILES