title: ERR_CONNECTION_RESET error when submitting html form with file input
body: <p>I am having a problem with uploading an image with a html form. When I submit the form after about 3-5 seconds I get the following error in the browser:</p>
  
  <blockquote>
    <p>ERR_CONNECTION_RESET</p>
  </blockquote>
  
  <p>The problem seems to be with images in the 100kb and greater range. Smaller images submit every time, but these larger images submit 1 out of maybe 10 tries. I've set higher values for <code>post max size</code>, <code>upload max file size</code> etc in the <code>.htaccess</code> file but that did not fix the problem.</p>
  
  <p>Here is my HTML form:</p>
  
  <pre><code>&lt;form method="post" name="update_form" action="php/editpost" enctype="multipart/form-data"&gt;
  
      &lt;div class="form-group"&gt; 
          &lt;label for="img_upload"&gt;Select image&lt;/label&gt;
          &lt;input type="file" name="img_upload" id="img_upload" class="form-control"&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt; 
          &lt;input class="btn btn-success btn-lg" type="submit" value="Update" name="edit_submit" id="edit_submit"&gt;
      &lt;/div&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>In PHP, I am using 'move_uploaded_file' to move the image to it's destination directory like:</p>
  
  <pre><code>if ($_FILES["img_upload"]["name"]) {
  
      $target_dir = "uploads/";
      $target_file = $target_dir . basename($_FILES["img_upload"]["name"]);
      $imgsrc = $target_file;
      $uploadOk = 1;
      $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  
      // Check if image file is a actual image and square
      $check = getimagesize($_FILES["img_upload"]["tmp_name"]);
      if($check !== false) {
          $width = $check[0];
          $height = $check[1];
          if ($width != $height) {
              $error = $error."&lt;br /&gt;- The image is not square, please crop it and try again.";
              $uploadOk = 0;
          } 
      } else {
          $error = $error."&lt;br /&gt;- File is not an image.";
          $uploadOk = 0;
      }
  
      // Check if file already exists
      if (file_exists($target_file)) {
          chmod($target_file,0755); // Change the file permissions
          unlink($target_file); // remove the file
      }
  
      // Check file size
      if ($_FILES["img_upload"]["size"] &gt; 1000000) {
          $error = $error."&lt;br /&gt;- Your image is too large.";
          $uploadOk = 0;
      }
  
      // Allow certain file formats
      if($imageFileType != "jpg" &amp;&amp; $imageFileType != "png" &amp;&amp; $imageFileType != "jpeg") {
          $error = $error."&lt;br&gt;- Only JPG, JPEG &amp; PNG images are allowed.";
          $uploadOk = 0;
      }
  
      // Check if $uploadOk is set to 0 by an error
      if ($uploadOk == 0) {
          $fail .= "There were error(s) while uploading the image:&lt;br /&gt;".$error;
      }
  
      // if everything is ok, try to upload file
      else {
  
          if (move_uploaded_file($_FILES["img_upload"]["tmp_name"], $target_file)) {
  
              $sql = mysqli_query($link,"UPDATE `posts` SET `imagesrc`='$imgsrc' WHERE `postid`='$postid' LIMIT 1");
  
              if ($sql) {
                  $success .= '- Image updated successfully.&lt;br /&gt;';
              }  else {
                  $fail .= "- Failed to update the image.&lt;br /&gt;";
              }
          }
      } 
  }
  
  header("location:../admincontrol?result_s=".urlencode($success)."&amp;result_f=".urlencode($fail));
  exit();
  </code></pre>
  
  <p>Any help would be much appreciated, I included all this code but I think it's probably something that needs to be set in <code>.htaccess</code> or <code>php.ini</code>?</p>