How to get File-Type of an Image in a HTML page?
<p>I've wrote a short script to upload images from a URL so as not to hotlink to them. If the image extension is not a .jpeg then the image that is uploaded is broken. I can't figure out how to preserve the file extension or filename so I've had to add a timestamp to them and a static extension.</p>

<pre><code>&lt;?php

    ini_set('user_agent', 'TEST/1.0 +http://127.0.0.1');

    require_once('simple_html_dom.php');

    // Create DOM from URL
    $html = file_get_html('http://www.discogs.com/viewimages?release='.$_POST["album_id"]);

    // Grab the coverart
    $img = $html-&gt;find('.image_frame', 0);

    $url = $img-&gt;src;

    $file = file_get_contents($url);

    $image = 'discogs_'.time().'_image.jpeg';

    file_put_contents('/path/to/file/'.$image,$file);

    echo $image;

?&gt;
</code></pre>

<p><strong>Updated code with Baba's help</strong>: <a href="http://codepad.org/3zH3B882" rel="nofollow">http://codepad.org/3zH3B882</a></p>
