检查用户是否使用PHP上传文件

时间:2012-04-25 05:03:56

标签: php html

我试着检查用户是否选择了上传的文件

HTML

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

PHP

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

我正在测试使用它不起作用。有没有其他方式

2 个答案:

答案 0 :(得分:1)

我会查看此位置以获取有关如何正确处理此案例的更多信息: http://www.php.net/manual/en/features.file-upload.multiple.php

答案 1 :(得分:1)

检查

            <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>';
                            }

                        }

                    }
                }


            ?>