duanhan5230 2016-11-29 13:34
浏览 10

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

I am using $_FILES for multiple file upload the problem is it is not validating the null condition i have two multiple input files and I want to check whether an image has been uploaded to a specific input type file and on the basis of that I am validating if input 1 has no image uploaded then do nothing I went through dozens of examples on the internet but still it is running both blocks. Here's my code:

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

<?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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么