0
//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>

上传.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:\n"; 
        var_dump($post); 
    } 
    else { 
        print "We have " . count($empty) . " empty values\n"; 
        print "Posted:\n"; 
        var_dump($post); 
        print "Empty:\n"; 
        var_dump($empty); 
        exit; 
    }
?>

问题:当我列出所有 $post 值时,我只得到静态的“提交”按钮。我可以根据条件查看所有生成的文件上传控件。但无法在upload.php 文件中获得控制权。您能否建议代码中是否有任何问题。我是 PHP 新手。提前感谢您的投入。

谢谢 - Abhik Banerjee

4

2 回答 2

0

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.

于 2013-03-08T10:58:31.137 回答
0

您可以从 $_FILES 获取文件详细信息

于 2013-03-08T11:32:11.143 回答