文件上传未在null输入上验证

时间:2016-11-29 13:35:00

标签: php

我正在使用$_FILES进行多个文件上传问题是它没有验证空条件我有两个多输入文件,我想检查一个图像是否已上传到特定的输入类型文件和我的基础是验证输入1是否没有上传图像然后什么都不做我在互联网上经历了几十个例子,但它仍在运行两个块。这是我的代码:

<form method="post" action="flyers_admin_process.php" enctype='multipart/form-data'>
                        <h4 style="margin-bottom: 8%;">Add flyers for Canada(You Can Choose multiple Files)</h4>
                        <div style="margin-top: 2%;margin-bottom: 6%" class="uk-width-large-1 uk-width-medium-1-1">
                            <input type="file" id="fileName" name="fileName[]" multiple>
                        </div>

                    <h4 style="margin-bottom: 8%;">Add flyers for USA(You Can Choose multiple Files)</h4>
                    <div style="margin-top: 2%;margin-bottom: 6%" class="uk-width-large-1 uk-width-medium-1-1">
                        <input type="file" id="fileName2" name="fileName2[]" multiple>
                    </div>
                        <input type="submit" />
                    </form>

flyers_admin_process.php文件

<?php
include "db.php";
if($_SERVER['REQUEST_METHOD']=="POST") {

    if(!empty($_FILES["fileName"]["name"])) {
        echo "inside 1";
        $path = "flyers_canada/"; // Upload directory
        $count = 0;
        foreach ($_FILES['fileName']['name'] as $f => $name) {
            if(move_uploaded_file($_FILES["fileName"]["tmp_name"][$f], $path.$name))
                $filetmp = $_FILES["fileName"]["tmp_name"][$f];
            $filename = $_FILES["fileName"]["name"][$f];
            $filepath = "flyers_canada"."/".$filename;
            $query="INSERT INTO `flyers_canada`(`path`) VALUES (?)";
            $stmt = $db->prepare($query);
            if($stmt){
                $stmt->bind_param("s",$filepath);
                $stmt->execute();
                $stmt->close();
            }



            $count++; // Number of successfully uploaded file
        }

    }



        if(!empty($_FILES["fileName2"]["name"])) {
        echo "inside 2";
        $path = "flyers_usa/"; // Upload directory
        $count = 0;
        foreach ($_FILES['fileName2']['name'] as $f => $name) {
            if(move_uploaded_file($_FILES["fileName2"]["tmp_name"][$f], $path.$name))
                $filetmp = $_FILES["fileName2"]["tmp_name"][$f];
            $filename =  $_FILES["fileName2"]["name"][$f];
            $filepath = "flyers_usa"."/".$filename;
            $query="INSERT INTO `flyers_usa`(`path`) VALUES (?)";
            $stmt = $db->prepare($query);
            if($stmt){
                $stmt->bind_param("s",$filepath);
                $stmt->execute();
                $stmt->close();
            }



            $count++; // Number of successfully uploaded file
        }

    }

    ?>
    <script language="javascript">
       // alert('Flyer has been added succesfully!');
       // location.href = "flyers-admin.php";
    </script>
    <?php
}
?>

0 个答案:

没有答案