2015-03-03 118 views
0

每当用户点击提交,它应该检查并看看提交按钮是否被击中。出于某种原因,虽然它只是忽略它。基本上我想要做的是检查用户是否上传了图片,然后检查他们上传的图片。然而,这似乎并没有工作:(这里是我的代码:POST不检查按钮表单提交

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

回答

2

的问题(问题)是你检查一个场的存在不存在:

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

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