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

时间:2015-04-29 07:22:45

标签: javascript php jquery mysql

我已经尝试了以下代码来捕获图像,它将图像存储在指定的文件夹中,但我想要存储在数据库中的图像路径不起作用。代码的执行在Uploding之后停止。 .. message.Please帮我,我的代码出了什么问题。



<!--test.php-->
<?php
session_start();
include 'connection.php';
$name = date('YmdHis');
$newname=mysql_real_escape_string("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;
<!--index.php-->
<?php
session_start();
if(isset ($_POST["send"]))
{
    $getname=$_POST["myname"];
    include 'connection.php';
    $idvalue=$_SESSION["myvalue"];
    $sql="update entry set name='$getname' where id='$idvalue'";
    $result=mysql_query($sql)
            or die(mysql_error());
    if($result)
    {
        echo "Uploaded $_SESSION[myvalue] re ..... ";
    }
    else
    {
        echo "$_SESSION[myvalue] nahi hua";
    }
}
?>

<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
    <input type="text" name="myname" id="myname">
    <input type="submit" name="send" id="send">
</form>

<script type="text/javascript" src="webcam.js"></script>
<script language="JavaScript">
		document.write( webcam.get_html(320, 240) );
</script>
<form>
		<input type=button value="Configure..." onClick="webcam.configure()">
		&nbsp;&nbsp;
		<input type=button value="Take Snapshot" onClick="take_snapshot()">
	</form>

<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>
<div id="upload_results" style="background-color:#eee;"></div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

而不是在file_get_contents()给出相对路径给出完整路径/实际路径。

希望这对你有所帮助。