title: How to make an attachment button in php? I don't mean styling the original button but using an image as a button
body: <p>I am making a <strong>Mail Compose Page</strong>.</p>
  
  <blockquote>
    <p>I want to give the user an option to attach a file.
    I also want to make the attachment button as an image which I already have.</p>
  </blockquote>
  
  <p>I have made an image button but the image is acting like a submit button.
  But I want it to be an <em>Browse</em> button.</p>
  
  <p>My form is:</p>
  
  <pre><code>&lt;form method="post" action="" enctype="multipart/form-data"&gt;
      To: &lt;span class="error"&gt;* &lt;?php $receiverIdErr ?&gt;&lt;/span&gt;
      &lt;select id="receiverId" name="receiverId"&gt;
          &lt;?php
              $conn = connect();
              $receiverIdQuery = "SELECT Email FROM Users";
              $receiverIdResult = $conn-&gt;query($receiverIdQuery);
              if($receiverIdResult-&gt;num_rows &gt; 0) {
                  while($row = $receiverIdResult-&gt;fetch_assoc()) {
                      $Email = $row["Email"];
                      echo "&lt;option value=\"$Email\"&gt;" . $row["Email"] . "&lt;/option&gt;";
                  }
              }
          ?&gt;
      &lt;/select&gt;
      &lt;br /&gt;&lt;br /&gt;
      Subject: &lt;input type="text" name="Subject" required&gt;
      &lt;br /&gt;&lt;br /&gt;
      Body: &lt;span class="error"&gt;* &lt;?php $BodyErr ?&gt;&lt;/span&gt;
      &lt;textarea name="Body" rows="10" cols="100" maxlength="300" required&gt;
      &lt;/textarea&gt;
      &lt;br /&gt;&lt;br /&gt;
      Attachment:
      &lt;input type="image" src="paperclip4_black.png" width="20" height="20" name="myFile" id="myFile"&gt;
      &lt;br /&gt;&lt;br /&gt;
      &lt;input type="submit" name="Send" value="Send"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And my PHP is:</p>
  
  <pre><code>&lt;?php
  $BodyErr = $receiverIdErr = "";
  $Body = $Subject = $receiverId = $filePath = "";
  
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
      $Subject = test_input($_POST["Subject"]);
  }
  
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
      if (empty($_POST["Body"]))
          $BodyErr = "Body is required";
      else
          $Body = test_input($_POST["Body"]);
  }
  
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
      if (empty($_POST["receiverId"]))
          $receiverIdErr = "Choose a receiver";
      else
          $receiverId = test_input($_POST["receiverId"]);
  }
  
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
      if (isset($_FILES["myFile"]["name"])) {
          $target_dir = "asset/attachments/" . time();
          $target_file = $target_dir . basename($_FILES["myFile"]["name"]);
          $uploadOk = 1;
          $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  
          if ($uploadOk == 0) {
              $message = "Sorry, your file was not uploaded.&lt;br /&gt;";
          }
          else {
              if (move_uploaded_file($_FILES["myFile"]["tmp_name"], $target_file)) {
                  $filePath = $target_file;
              }
              else {
                  $filePath = $target_file;
              }
          }   
      }
  }
  ?&gt;
  </code></pre>