如何使用 php 将捕获的图像路径存储在 mysql 数据库中

How to store captured image path in mysql database using php.?

本文关键字:存储 路径 mysql 数据库 图像 php 何使用      更新时间:2023-09-26

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

<script src="webscript.js"></script>
	<!-- First, include the Webcam.js JavaScript Library -->
	<script type="text/javascript" src="webcam.min.js"></script>
	<script type="text/javascript" src="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>
<?php
include 'connection.php';  
    // be aware of file / directory permissions on your server
    $newname = move_uploaded_file($_FILES['webcam']['tmp_name'], 'uploads/webcam'.date('YmdHis').rand(383,1000).'.jpg');
    $query = "INSERT INTO entry(name) VALUES('".$_GET['url']."')";
    mysql_query($query)or die(mysql_error());
	echo "<script>alert('successfully..');</script>";
?>
<!DOCTYPE html>
<html>
<head>
<title>Javascript Webcam</title>
<link href="font-awesome.min.css" rel="stylesheet"/>
<link href="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" onClick="take_snapshot()">
	</form>
	<div id="results" class="well">Your captured image will appear here...</div>
 </div>
</div>
</center>
 
</body>
</html>

假设$mysqli是一个成功连接的[new Mysqli]对象。

$query = "SELECT * FROM 'database.table' WHERE 'somecolumn'='someval' LIMIT= 5";
if ($stmt = $mysqli->prepare($query)) {
/* execute statement */
$stmt->execute();
/* bind result variables */
$stmt->bind_result($name, $code);
/* fetch values */
while ($stmt->fetch()) {
    printf ("%s (%s)'n", $name, $code);
}
/* close statement */
$stmt->close();