2015-04-29 44 views
1

我試過以下代碼捕獲圖像,它將圖像存儲在指定的文件夾中,但我想要存儲在數據庫中的圖像的路徑不起作用。執行代碼在Uploding ... message之後停止。請幫助我,我的代碼出了什麼問題。如何在mysql數據庫中存儲網絡攝像頭捕獲的圖像路徑

<!--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) { 
 
\t print "ERROR: Failed to write data to $filename, check permissions\n"; 
 
\t 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"> 
 
\t \t document.write(webcam.get_html(320, 240)); 
 
</script> 
 
<form> 
 
\t \t <input type=button value="Configure..." onClick="webcam.configure()"> 
 
\t \t &nbsp;&nbsp; 
 
\t \t <input type=button value="Take Snapshot" onClick="take_snapshot()"> 
 
\t </form> 
 

 
<script language="JavaScript"> 
 
\t \t document.write(webcam.get_html(320, 240)); 
 
</script> 
 

 
<script language="JavaScript"> 
 
    webcam.set_api_url('test.php'); 
 
\t \t webcam.set_quality(90); // JPEG quality (1 - 100) 
 
\t \t webcam.set_shutter_sound(true); // play shutter click sound 
 
\t \t webcam.set_hook('onComplete', 'my_completion_handler'); 
 

 
\t \t function take_snapshot(){ 
 
\t \t \t // take snapshot and upload to server 
 
\t \t \t document.getElementById('upload_results').innerHTML = '<h1>Uploading...</h1>'; 
 
\t \t \t webcam.snap(); 
 
\t \t } 
 

 
\t \t function my_completion_handler(msg) { 
 
\t \t \t // extract URL out of PHP output 
 
\t \t \t if (msg.match(/(http\:\/\/\S+)/)) { 
 
\t \t \t \t // show JPEG image in page 
 
\t \t \t \t document.getElementById('upload_results').innerHTML ='<h1>Upload Successful!</h1>'; 
 
\t \t \t \t // reset camera for another shot 
 
\t \t \t \t webcam.reset(); 
 
\t \t \t } 
 
\t \t \t else {alert("PHP Error: " + msg); 
 
\t \t \t } 
 
\t \t } 
 
\t </script> 
 
<div id="upload_results" style="background-color:#eee;"></div>

回答

1

,而不是在file_get_contents()給予相對路徑充分路徑/實際路徑。

希望這可以幫助你。

+0

我試過但給了syntaxError:畸形的十六進制字符轉義序列 –

相關問題