title: Open file dialog and submit image by clicking an image
body: <p>I'm trying to upload an image by clicking on an existing image in a certain element. </p>
  
  <p>So the user will click on an image, the file upload dialog will show, and when the user selects an image from the file dialog the form automatically submits the form and reloads page.</p>
  
  <p>Here is some code I have:</p>
  
  <pre><code>$(document).ready(function() {
          $('#profile').click(function(e){
              $('#fileUploadField').click();
              e.preventDefault();
          });
      header('Location: ' . $current_file);
      });
  
  &lt;form action="" method="post" enctype="multipart/form-data"&gt;
      &lt;input type="file" name="profile" id="fileUploadField"&gt; &lt;input type="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>the profile div is where the image is contained</p>
  
  <p>I already have the code to show the image. I just need to open the dialog, and on close, submit the form and refresh page.</p>
  
  <p>Here is my other code:</p>
  
  <pre><code>&lt;?php
          if (isset($_FILES['profile']) === true) {
              if (empty($_FILES['profile']['name']) === true) {
                  echo 'Please choose a file!';
              } else {
                  $allowed = array('jpg', 'jpeg', 'gif', 'png');
  
                  $file_name = $_FILES['profile']['name'];
                  $file_extn = strtolower(end(explode('.', $file_name)));
                  $file_temp = $_FILES['profile']['tmp_name'];
  
                  if (in_array($file_extn, $allowed) === true) {
                      change_profile_image($session_user_id, $file_temp, $file_extn);
  
                      header('Location: ' . $current_file);
                      exit();
  
                  } else {
                      echo 'Incorrect file type. Allowed: ';
                      echo implode(', ', $allowed);
                  }
              }
          }
  
          if (empty($user_data['picture']) === false) {
              echo '&lt;img src="', $user_data['picture'], '" alt="', $user_data['firstname'], '\'s Profile Image" style="height:100px"&gt;';
          }
          ?&gt;
  </code></pre>