title: How to pass a file type input into javascript and use it into another php page?
body: <p>Hello and good day everyone! I am here to ask on how to pass a file type using javascript, so that I can use it to another php page. The following is an input for type file:</p>
  
  <pre><code>&lt;input type="file" name="imgCompany" id="imgCompany"&gt;
  </code></pre>
  
  <p>I am getting the file like this in php:</p>
  
  <pre><code>$file = $_FILES['imgCompany']['tmp_name'];
  </code></pre>
  
  <p>The first question I have to ask is how can I get the $file variable to be place in a javascript function? (same php page). So far this was my attempt to do so:</p>
  
  <pre><code>function addImage() {
    var companyImage = $('#imgCompany').val();
  }
  </code></pre>
  
  <p>The second question I have to ask how do I pass that file value once it is declared in the addImage() function using a method like this:</p>
  
  <pre><code>$.post('addImage.php', {postimage:file},
  function(data)
  {
      //returns the echoed value from the php file
      $('#result').html(data);
  });
  </code></pre>
  
  <p>Or is there another way?</p>
  
  <p>I am going to use what I pass from the post to another php page, so I can upload that image into a database. I am uploading this image into a database like this:</p>
  
  <pre><code>    ...
      $image = addslashes (file_get_contents($_FILES['image']['tmp_name']));
      //$image_name = addslashes ($_FILES['image']['name']);
      $image_size = getimagesize($_FILES['image']['tmp_name']);
  
      if ($image_size == FALSE)
          echo "&lt;h3 class='warningStyle' align='center' style='position:absolute; top:235px; left:660px;'&gt;No Image was Selected&lt;/h3&gt;";
      else {
  
          if (!$insert = $db-&gt;query ("INSERT INTO company VALUES('','$companyName','$image')"))
              echo "&lt;h3 class='warningStyle' align='center' style='position:absolute; top:235px; left:650px;'&gt;Problem uploading the image&lt;/h3&gt;";
      else {
          echo "&lt;h3 class='successStyle' align='center' style='position:absolute; top:235px; left:620px;'&gt;Company Account successfully created&lt;/h3&gt;";
      }
  
  }
  </code></pre>