我想从网络摄像头用户图像中捕获图像,使用php将存储在指定文件夹中的图像和捕获的图像路径存储到mysql中。 我有一个问题,网络摄像头捕获的图像路径没有存储在mysql数据库中。所以请帮帮我......
<script type="text/javascript" src="webcam.js"></script>
<script language="JavaScript">
document.write( webcam.get_html(320, 240) );
</script>
<script language="JavaScript">
webcam.set_api_url( 'test.php' );
webcam.set_quality( 90 ); // JPEG quality (1 - 100)
webcam.set_shutter_sound( true ); // play shutter click sound
webcam.set_hook( 'onComplete', 'my_completion_handler' );
function take_snapshot(){
// take snapshot and upload to server
document.getElementById('upload_results').innerHTML = '<h1>Uploading...</h1>';
webcam.snap();
}
function my_completion_handler(msg) {
// extract URL out of PHP output
if (msg.match(/(http\:\/\/\S+)/)) {
// show JPEG image in page
document.getElementById('upload_results').innerHTML ='<h1>Upload Successful!</h1>';
// reset camera for another shot
webcam.reset();
}
else {alert("PHP Error: " + msg);
}
}
</script>
&#13;
-------------------------------------
____________test.php_________________
<?php
session_start();
include 'connection.php';
$name = date('YmdHis');
$newname="images/".$name.".jpg";
$file = file_put_contents( $newname, file_get_contents('php://input') );
if (!$file) {
print "ERROR: Failed to write data to $filename, check permissions\n";
exit();
}
else
{
$sql="Insert into entry(images) values('$newname')";
$result=mysql_query($con,$sql)
or die("Error in query");
$value=mysql_insert_id($con);
$_SESSION["myvalue"]=$value;
}
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' . $newname;
print "$url\n";
?>
&#13;
<form>
<input type=button value="Configure..." onClick="webcam.configure()">
<input type=button value="Take Snapshot" onClick="take_snapshot()">
</form>
<div id="upload_results" style="background-color:#eee;"></div>
&#13;
答案 0 :(得分:0)
所以你说一切都有效,除了&#34;插入条目(图像)值(&#39; $ newname&#39;)&#34;?
尝试回显完整的mySQL错误而不是简短的&#34;查询错误&#34;。它可能是表不存在,列不存在,它没有自动增量列,另一个未命名列没有默认值......可能是任何东西。