如何使用php在mysql数据库中存储网络摄像头捕获的图像路径。

时间:2015-05-04 08:38:36

标签: javascript php mysql

我想从网络摄像头用户图像中捕获图像,使用php将存储在指定文件夹中的图像和捕获的图像路径存储到mysql中。我有一个问题,网络摄像头捕获的图像路径没有存储在mysql数据库中。所以请帮帮我......

JS



 <script src="js/webscript.js"></script>

    	<!-- First, include the Webcam.js JavaScript Library -->
    	<script type="text/javascript" src="js/webcam.min.js"></script>
    	<script type="text/javascript" src="js/script.js"></script>
    	
    	<!-- Configure a few settings and attach camera -->
    	<script language="JavaScript">
    		Webcam.set({
    			width: 320,
    			height: 240,
    			image_format: 'jpeg',
    			jpeg_quality: 90
    		});
    		Webcam.attach( '#my_camera' );
    		
    		var shutter = new Audio();
    		shutter.autoplay = false;
    		shutter.src = navigator.userAgent.match(/Firefox/) ? 'shutter.ogg' : 'shutter.mp3';
    		
    		function take_snapshot() {
    			// take snapshot and get image data
    			Webcam.snap( function(data_uri) {
    				// display results in page
    				document.getElementById('results').innerHTML = 
    					'<h2>Here is your image:</h2>' + 
    					'<img src="'+data_uri+'"/>';
    					Webcam.upload( data_uri, 'upload.php', function(code, text) {
    						alert(data_uri);
    					});
    			} );
    		}
    		
    	</script>
&#13;
**PHP**

    <?php
    	include 'connection.php';   
    	 
        $path = 'uploads/webcam'.date('YmdHis').rand(383,1000).'.jpg';
move_uploaded_file($_FILES['webcam']['tmp_name'], $path);
        $query = "INSERT INTO entry(name) VALUES('".$path."')";
        mysql_query($query)or die(mysql_error());
 
    ?>

**HTML**
&#13;
<!DOCTYPE html>
    <html>
    <head>
    <title>Javascript Webcam</title>
    <link href="css/font-awesome.min.css" rel="stylesheet"/>
    <link href="css/bootstrap.min.css" rel="stylesheet"/> 
    </head>
    <body>
    <center>
    <div class="row">
     <div class="col-md-6"> 
    	<h3>Profile Picture</h3>
    	<div id="my_camera"></div>
    	<!-- A button for taking snaps -->
    	<form>
    		<input type=button class="btn btn-success" value="Take Snapshot" name="sub" onClick="take_snapshot()">
    	</form>
    	<div id="results" class="well">Your captured image will appear here...</div>
     </div>
    </div>
    </center>
      </body>
    </html>
     
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

javascript函数  Webcam.set({         宽度:260,         身高:260,         image_format:&#39; jpeg&#39;,         jpeg_quality:90,         force_flash:false     });     Webcam.attach(&#39;#my_camera&#39;);

function take_snapshot() {

    // take snapshot and get image data
    Webcam.snap(function (data_uri) {
        // display results in page

        document.getElementById('results').innerHTML =
            '<h3>Here is your image....</h3>' +
            '<img src="' +data_uri+ '" width=\'280px\' height=\'250px\'/>';

        Webcam.upload(data_uri, 'saveimages.php', function (code, text) {

                alert(data_uri);
        });
    });
    Webcam.reset();
}

php函数:  require_once&#39; core / init.php&#39;;

$path = 'images/saved_images/webcam'.date('YmdHis').rand(383,1000).'.jpg';
move_uploaded_file($_FILES['webcam']['tmp_name'], $path);
$query = "INSERT INTO trial(image) VALUES('".$path."')";
$db->query($query);
echo "<script>alert('successfully..');</script>";

HTML:                    拍一张照片