POST不检查按钮表单提交

时间:2015-03-03 00:28:47

标签: php html css

每当用户点击提交时,都应该检查并查看提交按钮是否被点击。出于某种原因,虽然它只是忽略它。基本上我想做的就是检查并查看用户是否上传了图像,然后检查他们上传的图像。但它似乎不起作用:(这是我的代码:

<div class="col-xs-12">
    <form action="" method="post" enctype="multipart/form-data">
        <div class="col-xs-12" id="fileuploadbuttontitle">
            Change Picture
        </div>

        <div class="col-xs-12" id="fileuploadbutton">
            Select Image
            <input type="file" name="image">
        </div>

        <div class="col-xs-12">
            <button type="submit" name="uploadimage" id="fileuploadbuttonsubmit"> Upload Image </button>
        </div>
    </form>
<?php
    if (isset($_POST["uploadimage"])) {
        //variables
        $target_dir = "pictures/";
        $target_file = $target_dir . basename($_FILES["image"]["name"]);
        $uploadOk = 1;
        $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

        //tests
        $imagetest = False;
        $imagesizetest = False;
        $imageformattest = False;

        //Checks to see if upload is a image
        if(isset($_POST["submit"])) {
            $check = getimagesize($_FILES["image"]["tmp_name"]);
            if($check == False) {
?>
                <div id="allinputboxerroraboutbox" class="col-xs-12 col-sm-7"> Photo is invalid. </div>
<?php
                $imagetest = False;
            }
            else {
                $imagetest = True;

                //File Size
                if ($_FILES["image"]["size"] > 15000) {
?>
                    <div id="allinputboxerroraboutbox" class="col-xs-12 col-sm-7"> Photo is too big. Maxium 15 KB. </div>
<?php
                    $imagesizetest = False;
                }

                else {
                    $imagesizetest = True;

                    //File Format
                    if(($imageFileType == "jpg") or ($imageFileType == "png") or ($imageFileType == "jpeg") or ($imageFileType == "gif")) {
?>
                        <div id="allinputboxerroraboutbox" class="col-xs-12 col-sm-7"> Photo is not a valid format. JPG, JPEG, PNG, or GIF. </div>
<?php
                        $imageformattest = False;
                    }

                    else {
                        $imageformattest = True;

                        //Final Check
                        if (($imagetest) and ($imagesizetest) and ($imageformattest)) {
                            if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file . "test")) {
?>
                                <meta http-equiv='refresh' content="0; url=http://localhost/postin'/profiles/<?php print utf8_decode($loggedin_session_permalink); ?>"
<?php
                            }
                            else {
?>  
                                <div id="allinputboxerroraboutbox" class="col-xs-12 col-sm-7"> There is a error. </div>
<?php
                            }
                        }
                    }
                }
            }
        }
    }
?>

1 个答案:

答案 0 :(得分:2)

问题(问题)是您正在检查是否存在不存在的字段:

if(isset($_POST["submit"]))

没有名为submit的字段。提交字段名为uploadimage,您已经检查过它。如果要检查文件是否已上载,请检查$_FILES变量。 This SO question可能会对您有所帮助。