简体   繁体   English

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

[英]PHP : Unidentified Index Error on File Upload

This is my code. 这是我的代码。 I am getting an unidentified index error for the name of the file ie 'userfile'. 我收到一个未识别的索引错误的文件名称,即'userfile'。 It's a very basic code but I don't get where I am going wrong. 这是一个非常基本的代码,但我没有得到我错的地方。

<!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>

This should work to print file content 这应该可以打印文件内容

<!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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM