PHP: Simple upload image url to ImageShack
Filed Under (php) by The Chef on 26-04-2009
Tagged Under : ImageShack, php, upload, url
Here is a function you can use to directly upload url images to ImageShack. The function returns an associative array with 2 elements representing the ImageShack url of the image and of the thumbnail
function uploadURLToImageshack($url)
{
$ch = curl_init ( "http://www.imageshack.us/transload.php" );
$post ['xml'] = 'yes';
$post ['url'] = $url;
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_HEADER, false );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_TIMEOUT, 60 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, array (
'Expect: ' ) );
$result = curl_exec ( $ch );
curl_close ( $ch );
if (strpos ( $result, '<' . '?xml version="1.0" encoding="iso-8859-1"?>' ) === false)
{
return NULL;
} else
{
$xml = new SimpleXMLElement ( $result );
return array (
"image" => $xml->image_link,
"thumb" => $xml->thumb_link );
}
}