繁体   English   中英

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

[英]How to store webcam captured image path in mysql database

我尝试了以下代码来捕获图像,它将图像存储在指定的文件夹中,但是我要存储在数据库中的图像的路径不起作用。 ,我的代码出了什么问题。

 <!--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"; ?> 
 <!--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> 

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

希望这对您有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM