1
我有一个脚本,可以从网络摄像头捕获图像并将其存储在使用php的目录中。使用PHP从网络摄像头或浏览文件上传图像
这里是我的html代码
<script type="text/javascript" src="scripts/webcam.js"></script>
<script>
$(function(){
//give the php file path
webcam.set_api_url('saveimage.php');
webcam.set_swf_url('scripts/webcam.swf');//flash file (SWF) file path
webcam.set_quality(100); // Image quality (1 - 100)
webcam.set_shutter_sound(true); // play shutter click sound
var camera = $('#camera');
camera.html(webcam.get_html(300, 200)); //generate and put the flash embed code on page
$('#capture_btn').click(function(){
//take snap
webcam.snap();
$('#show_saved_img').html('<h3>Please Wait...</h3>');
});
//after taking snap call show image
webcam.set_hook('onComplete', function(img){
$('#camera_wrapper').html('<img src="' + img + '">');
//reset camera for the next shot
//$("#camera_wrapper").html(' ');
//webcam.hide();
});
});
</script>
<!-- camera screen -->
<div id="camera_wrapper">
<div id="camera"></div>
<br />
<button id="capture_btn">Capture</button>
</div>
<!-- show captured image -->
<div id="show_saved_img" ></div>
PHP代码,用于存储图像
$filename = time() . '.jpg';
$filepath = 'saved_images/';
$result = file_put_contents($filepath.$filename, file_get_contents('php://input'));
if (!$result) {
print "ERROR: Failed to write data to $filename, check permissions\n";
exit();
}
echo $filepath.$filename;
?>
这个脚本工作正常。但是我想补充连同浏览文件选项这个。即用户可以使用其摄像头捕获图像,或者可以从设备上浏览文件。
我是javascript的新手。是否可以添加两个选项
我需要两个选项**网络摄像头**和**选择文件** –
因此,编辑代码并添加您的文档r代码已经适用于摄像头。 – mayorsanmayor