title: php/curl - get extension of image on remote server using headers
body: <p>There is a form on my website that allows the upload of images from a remote server. When the user enters the link and submits, I want to check the file and make sure it's the right extension before I copy it off to my server.</p>
  
  <p>I tried to directly use exif_imagetype, but allow_url_fopen is not allowed on the server so need help. I think using curl will solve the problem, but I'm not sure how to get the image extension from the header.</p>
  
  <p>Thanks in advanced!</p>
  
  <hr>
  
  <h2>solution</h2>
  
  <pre><code>$ch = curl_init ($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_exec ($ch);
  
  $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
  echo $content_type;
  </code></pre>
  
  <p>Thanks to Mario!</p>