title: How to get HTTP header (Content-Type) from URL with Javascript
body: <p>Good afternoon! Here is what I am trying to achieve.</p>
  
  <p>I have an input which allow the user to enter an URL (mostly for images) but it can also be a different type of file. I am searching for a way to verify that the url exists and also get the mime type.</p>
  
  <p>Here is a <a href="https://jsfiddle.net/r2jf74dm/" rel="nofollow" title="jsfiddle">jsfiddle</a> of my javascript tests.</p>
  
  <p>I found a way to do it using a PHP and AJAX with a function like that:</p>
  
  <p>PHP:</p>
  
  <pre><code>function get_url_content_type( $url ) {
  
      $header = get_headers( $url, 1 );
  
      if ( isset( $header['Content-Type'] ) ) {
  
          return $header['Content-Type'];
      }
  }
  </code></pre>
  
  <p>I am not sure that is the right way to do it, does anyone have better ideas?</p>
  
  <p>Many thanks!</p>