php fopen fread images
<p>I am trying to <code>tcp</code> an image from my linux php ec2 instance to another server. <br />
when i echo out the contents of <code>fopen</code> and <code>fread</code> i can see the image is processed but only halfway <br />
Does anyonew know what is causing this please, thank you.</p>

<pre><code>$imageURL = 'http://ec2-**-***-**-**.compute-1.amazonaws.com/New_Era_For_NASA_2.jpg';
$ch = curl_init($imageURL);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch);
//echo $data;
curl_close($ch);
if ($data === false) {
        die('cURL failed');
}
if ( preg_match('/Content-length: (\d+)/', $data, $matches) || preg_match('/Content-Length: (\d+)/', $data, $matches) ) {
        $size = (int)$matches[1];
}   

$fileHandle = fopen($imageURL, 'rb'); //r or rb
$fileData = fread( $fileHandle, $size );
//echo $fileData;
fclose( $fileHandle );
$data = $fileData;

header('Content-type: image/jpeg'); 
echo $data;
</code></pre>

<p><img src="http://i.stack.imgur.com/vRD3z.jpg" alt="enter image description here"></p>
