CURL with image

This is the snippet I use for showing images from internally on my network. The idea is that only the web server is exposed to the internet, so it isn’t possible to directly change anything on the picture server.

<?php
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,"http://10.0.0.50:8080/camera.jpg");
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

if (empty($buffer))
	{
		print "Picture unavalible";
	}
	else
	{
		header('Content-Type: image/jpeg');
		print $buffer;
	}
?>

Leave a Reply