Akrambek
Akrambek

Reputation: 89

check if user uploaded a file in PHP

I am try to check whether user choose uploaded file or not

html

<input  type=\"file\" name=\"upload1[]\" multiple />

php

if(is_uploaded_file($_FILES['upload1']['tmp_name'])){
    echo 'ok';
}

I am testing using it doesn't work. is there any other way

Upvotes: 0

Views: 297

Answers (2)

Asif
Asif

Reputation: 256

Check this

            <form enctype="multipart/form-data" method="POST">
                Choose a file to upload:
                <input type="file" name="upload1[]" multiple />
                <br />
                <input type="submit" value="Upload File" name="submit" />
            </form>
            <?php

                if (isset($_POST['submit'])) {

                    if (isset($_FILES['upload1'])) {


                        $counter = count($_FILES['upload1']['name']);
                        for ($i = 0; $i < $counter; $i++) {

                            if (is_uploaded_file($_FILES['upload1']['tmp_name'][$i])) {
                                echo $_FILES['upload1']['tmp_name'][$i] . ' - ok <br>';
                            }

                        }

                    }
                }


            ?>

Upvotes: 1

TheRealKingK
TheRealKingK

Reputation: 839

I would look at this location for further information on how to properly handle this case: http://www.php.net/manual/en/features.file-upload.multiple.php

Upvotes: 1

Related Questions