How to pass an variable to curl_init in php
<p>In the below code which is to download an file  , But i tried to pass an image url in the form of variable to the curl_init , How to use variable in curl_init </p>

<p>//   $downlaod="http://image.com/image.jpg";</p>

<p>I used $download variable in the curl_init but it shows errors. </p>

<pre><code>&lt;?php
$ch = curl_init('http://my.image.url/photo.jpg');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // buffer output (`true` if you will be  redirecting stream to the user, in $result will be your image content)
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); // because image is binary data

$result = curl_exec($ch); // executing requrest (here will be raw image data if  RETURNTRANSFER == true)
$response_code = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); // getting response code to  ensure that request was successfull
$content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); // getting return content-type

// Listing allowed image types    
$allowed_mimes = array(
        'image/jpeg',
        'image/gif',
        'image/png'
        );
if ($response_code == 200 AND in_array($content_type, $allowed_mimes) ) {
header( 'Content-Type: '.$content_type );
echo $result; // echoing image to STDOUT
} else
return false;
?&gt;
</code></pre>
