Doug Smith
Doug Smith

Reputation: 29316

Why isn't this PHP working? It says my $_FILES variable doesn't exist, when I think I have created it

<body>
    <div class="wrapper">

        <div class="header">
            <h1>Text2<span class="fancy">FairyTale</span></h1>
            <h4>Input: text, Output: <span class="fancy">fairy tale</span></h4>
        </div>

        <?php
            if ($_SERVER["REQUEST_METHOD"] == "POST") {

                echo "<pre>";
                print_r($_FILES);
                echo "</pre>";
                $filename = $_FILES["file-input"]["name"];
                $extension = pathinfo($filename, PATHINFO_EXTENSION);

                move_uploaded_file($_FILES["file-input"]["tmp_name"], $filename);
            }
        ?>

        <div class="upload-form">
            <form action="" method="post" encytype="multipart/form-data">
                <div class="upload">
                    <input type="file" name="file-input" class="file-input">
                    <input type="button" value="Browse">
                    <span class="filename">No file selected</span>
                </div>
                <input type="submit" name="submit" value="Upload">

                <span class="valid-formats">Valid input: .txt files &lt;= 512 KB</span>
            </form>
        </div>
    </div>
</body>

Upvotes: 0

Views: 183

Answers (1)

mohammad mohsenipur
mohammad mohsenipur

Reputation: 3149

you only write form Attribute Wrongly is Not encytype is enctype

 enctype="multipart/form-data" 

Upvotes: 4

Related Questions