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.
<?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->find('.image_frame', 0);
$url = $img->src;
$file = file_get_contents($url);
$image = 'discogs_'.time().'_image.jpeg';
file_put_contents('/path/to/file/'.$image,$file);
echo $image;
?>
Updated code with Baba’s help: http://codepad.org/3zH3B882
You can try using
getimagesizewithimage_type_to_extensionOutput