POST未检查按钮表单提交


POST Not Checking Button Form Submit

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

<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
                            }
                        }
                    }
                }
            }
        }
    }
?>

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

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

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