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