PHP:文件上载时出现未识别的索引错误

时间:2017-01-05 10:48:52

标签: indexing upload file-handling

这是我的代码。我收到一个未识别的索引错误的文件名,即' userfile'。这是一个非常基本的代码,但我不知道我哪里错了。

<!DOCTYPE html>
<html>
<head>
    <title>
        File Upload
    </title>
</head>
<body>
<h2> Your file contains : <br></h2>
<?php
        $handle = fopen($_FILES['userfile']['tmp_name'], "r");
        while (!feof($handle)) {
            $text = fgets($handle);
            echo $text, "<br/>";
        }
        fclose($handle);
?>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

这应该可以打印文件内容

<!DOCTYPE html>
<html>
<head>
    <title>
        File Upload 
    </title>
    <form name="myform" action="" method="post" enctype="multipart/form-data">
    <input type="file" name="userfile"/>
    <input type="submit" name="submit" value="submit">
    </form>
</head>
<body>
    <h2> Your file contains : <br> </h2>
            <?php
                    $file = file_get_contents($_FILES['userfile']['tmp_name']);
                    echo $file;
            ?> 
</body>
</html>