How to make your own Mobile WebCam Server
It is really easy to build in the capability of viewing your
Mobile WebCam to your webpage. There are two possible options:
- you provide only a web interface for viewing your webcam, the photos
are stored in your online album at www.mobile-mir.com,
- you provide a web interface and your photos are stored at your website.
To build a web interface your will need to create a html page, but
to create your own Mobile WebCam Server you will need to write
server side script.
We will show how to create the viewing part and the recieving part.
WebCam Viewer: HTML example
Create a new html-page with the following content:
<html>
<head><title>My Mobile WebCam</title></head>
<script language="JavaScript">
function go()
{
var now = new Date();
var stamp= parseInt(now.getTime() / 1000);
document.images.webcam.src="/path/image.jpg?"+stamp;
setTimeout("go()", 3000);
}
setTimeout("go()", 3000);
</script>
<body>
<div align="center">
My Mobile Web Cam<br>
<img src="/path/image.jpg" name="webcam">
</div>
</body>
</html>
Substitute the string "/path" with the right path to your webcam image.
If you store your webcam images at www.mobile-mir.com, login, go to
the "View WebCam"-page, press with the right button at the image of webcam,
and select "Properties", and copy the URL from there - it will be the right path
for your webcam.
(For example the path to the public webcam is http://www.mobile-mir.com/wc/users/publici1IXSf/webcamqKssGi/image.jpg)
This html example will refresh the picture every three seconds.
Receiver: PHP example
Your web server must support chuncked transfer encoding,
otherwise it will not work.
Create a new php-script with the following content:
<?
$log=$_GET['l'];// login
$mod=$_GET['m'];// mode
$uploaddir='/path/';
$numb=sizeof(scandir($uploaddir))+1;
$uploadfile = $uploaddir.$numb.".jpg";
if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{
echo "E5";// cannot upload
exit(0);
}
if($mod!=0)
{
copy($uploadfile,$uploaddir."image.jpg");
}
echo "OK";
?>
If you have an old verion of PHP, you will also need the following function.
(It should be inserted after the first symbols "<?")
function scandir($dir)
{
$dh = opendir($dir);
while (false !== ($filename = readdir($dh)))
$files[] = $filename;
return $files;
}
Substitute the string "/path/" with the right path to the directory
where you want to store the photos.
Remember that you need to set the correct rights for the upload directory...
Change the "/path" in the viewer example to the URL of upload directory.
Upload this script to your webserver, change Menu::Settings::Destination in the
midlet - and enjoy watching your webcam!
If you have a question or a suggestion - welcome to the forum... |