提交表单不会将数据传递给PHP

时间:2014-04-11 20:04:31

标签: php forms

提交表单似乎没有传递上传的文件。代码应该显示" array"何时上传文件。按下提交时没有任何反应

<?php
    $conn = mysql_connect("localhost","root","") or die(mysql_error());

    mysql_select_db ('coop',$conn);

    if(isset($_POST['submit']))
    {
        $file = $_FILES['file']['tmp_name'];

        $handle = fopen($file,"r");

        while(($fileop = fgetcsv($handle,1000,"|")) !== false)
        {
            echo $fileop;
        }
    }


?>


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Untitled</title>

</head>
<body>
        <form method="post" action="index.php" enctype="multipart/form-data">
            <input type="file" name="file" />
        </form>
        <br />
        <input type="submit" name="submit" value="submit">
</body>
</html>

2 个答案:

答案 0 :(得分:3)

您的<form> </form>标记应该包含表单的所有元素。如下所示:

<form method="post" action="index.php" enctype="multipart/form-data">
    <input type="file" name="file" />
    <br />
    <input type="submit" name="submit" value="submit">
</form>

答案 1 :(得分:1)

您的提交位于表单标记之外,修复您的HTML并且发布应该有效。