-1

So far i have this code which never stop loading

camera.php

$img = 'http://userid:password@ipaddress/mjpgstreamreq/1/image.jpg'; 
header ('content-type: image/jpeg'); 
readfile( $img ); 

index.html

<img src="camera.php" />
<!-- But this does not work -->

and if I have in a img tag on the page with this url as the src also never stop loading the page, and I am trying to read just the snapshot it is not a continues frames this is a recorded picture took with the ip camera, that I want to read and save in a file for future needs, and I am at localhost and the ip camera is in another network if it matters, so how can I read this without this continues loading.

2 Answers2

2

Try this out, but remember to change the username, password, ip and port on your Ip cam

<img src="http://myServer.com/cam.php" width="640" height="380" name="refresh">

<script language="JavaScript" type="text/javascript">     
  image = "http://myServer.com/cam.php"
  function Start() {
   tmp = new Date();
   tmp = "?"+tmp.getTime()
   document.images["refresh"].src = image+tmp
   setTimeout("Start()", 1000)
  }
    Start();       
</script>

<?php
 error_reporting(E_ALL);
 $img="IPCAM_IP:PORT/snapshot.cgi?user=UserName&pwd=Password"; 
 header ('content-type: image/jpeg');
 readfile($img); 
?> 
Allan Hansen
  • 106
  • 6
0

The resource you are requesting using readfile() is a motion JPEG stream, not just a single image. As such, the readfile() operation will never end — it will just keep on spitting out more images as the stream continues!

You will need to implement code to open the resource as an HTTP stream, parse out a single JPEG from the stream, and stop reading. This may not be simple.