<? xml version="1.0" ?> <! DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd" > < cross-domain-policy > < allow-access-from domain ="我的网站域名" /> </ cross-domain-policy >
然后修改网站上的有关截图的jpegcam文件:(upload.html和upload.php是根据jpegcam文件夹下test2.html和test.php修改而来)
upload.html这个是在线摄像头图片捕获的页面,webcam.set_api_url()设置url为其它服务器上接收post过来的数据的.php文件路径,
具体修改如下面红字部分。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JPEGCam Test Page 2</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Joseph Huckaby">
<!-- Date: 2008-03-15 -->
</head>
<body>
<table><tr><td valign=top>
<h1>JPEGCam Test Page 2</h1>
<h3>Demonstrates a two-step implementation: capture, then upload.</h3>
<!-- First, include the JPEGCam JavaScript Library -->
<script type="text/javascript" src="webcam.js"></script>
<!-- Configure a few settings -->
<script language="JavaScript">
webcam.set_api_url( 'http://www.xxxxx.com/upload.php' );
webcam.set_quality( 90 ); // JPEG quality (1 - 100)
webcam.set_shutter_sound( true ); // play shutter click sound
</script>
<!-- Next, write the movie to the page at 320x240 -->
<script language="JavaScript">
document.write( webcam.get_html(320, 240) );
</script>
<!-- Some buttons for controlling things -->
<br/><form>
<input type=button value="Configure..." onClick="webcam.configure()">
<input type=button value="Capture" onClick="webcam.freeze()">
<input type=button value="Upload" onClick="do_upload()">
<input type=button value="Reset" onClick="webcam.reset()">
</form>
<!-- Code to handle the server response (see test.php) -->
<script language="JavaScript">
webcam.set_hook( 'onComplete', 'my_completion_handler' );
function do_upload() {
// upload to server
document.getElementById('upload_results').innerHTML = '<h1>Uploading...</h1>';
webcam.upload();
}
function my_completion_handler(msg) {
// extract URL out of PHP output
if (msg.match(/(http/:/S+)/)) {
var image_url = RegExp.$1;
// show JPEG image in page
document.getElementById('upload_results').innerHTML =
'<h1>Upload Successful!</h1>' +
'<h3>JPEG URL: ' + image_url + '</h3>' +
'<img src="' + image_url + '">';
// reset camera for another shot
webcam.reset();
}
else alert("PHP Error: " + msg);
}
</script>
</td><td width=50> </td><td valign=top>
<div id="upload_results" style="background-color:#eee;"></div>
</td></tr></table>
</body>
</html>
upload.php(注意要有读写权限)文件接收从美国网站post过来的信息,要放在其它服务器上,作用获取upload.html捕获的图片,并写入文件,内容如下:
<? php /* JPEGCam Test Script */ /* Receives JPEG webcam submission and saves to local file. */ /* Make sure your directory has permission to write files as your web server user! */ $filename = date ( ' YmdHis ' ) . ' .jpg ' ; $result = file_put_contents ( $filename , file_get_contents ( ' php://input ' ) ); if ( ! $result ) { print " ERROR: Failed to write data to $filename , check permissions/n " ; exit (); } $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' . $filename; print " $url /n " ; ?>
这样做之后,图片可以保存到其它的服务器上,处理更灵活。