当前位置:  开发笔记 > 编程语言 > 正文

上传从网络摄像头生成的图像到mysql数据库与PHP无法正常工作

如何解决《上传从网络摄像头生成的图像到mysql数据库与PHP无法正常工作》经验,为你挑选了0个好方法。

尝试使用php将用户网络摄像头生成的图像插入mysql数据库,但它不起作用.我正在使用webcam.js,一切正常.当用户拍摄快照时,图像存储在服务器上,但是,mysql插件不执行插入作业.知道为什么它不工作?

两个代码如下所示:

cam.php:

session_start();

include_once 'dbconnect.php';//connection to db
if(!isset($_SESSION['user'])){//ensures that it the true user
    header("Location: index.php");  
}

//display current time 
//$arrival_time= date('Y-m-d H-i-s');
//echo "$arrival_time";

if (isset($_POST['send'])) {
    $getname= mysql_real_escape_string($_POST['last_name']);
    $idvalue= $_SESSION['myvalue'];

    $update=mysql_query("UPDATE `employees`.`webcam_clockin` 
        SET `last_name`='$getname' WHERE image_id='$idvalue'");

    if($update)
    {
        //run a check to verify last_name
        $sql=mysql_query("SELECT users.*, employees.* FROM users 
            NATURAL JOIN employees 
            WHERE employees.last_name='$getname'");
        $result=mysql_fetch_array($sql);

        if($result){
            $_SESSION['user'] = $result['user_id'];
            header("Location: home.php");
        }
        else
        {
            ?>
                
            

    
    
        
" method="post" class="form-signin" >
 

camsave.php:

session_start();
include_once 'dbconnect.php';

if(!isset($_SESSION['user']))
{
    header("Location: index.php");
}

//get some data about this user
$res2=mysql_query("SELECT users.*, employees.* FROM users  
    NATURAL JOIN employees WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res2);

if ($userRow) {
    echo "correct!!";
}
//Define storage location of original images
$folder = "images/";
$filename = date('Y-m-d-H-i-s') . '.jpg';
$original = $folder.$filename;

//Get JPEG snapshot from webcam
$input = file_get_contents('php://input');

//Blank images are discarded
if(md5($input) == '7d4df9cc423720b7f1f3d672b89362be'){
    exit();
}

//Retreive the snap and save to original dest.
$file= file_put_contents($original, $input);
if(!$file){
    print "ERROR: Failed to write data to $filename, check permissions\n";
    exit();
}
else
{
    //Get the size of the image
    $info = getimagesize($original);
    list($width,$height) = $info;
    if($info['mime'] != "image/jpeg"){//ensure we get right file extension
        unlink($original);
        exit();
    }
    //Move images to the Original folder
    rename($original, "images/original/".$filename);


    $emp_no = $userRow['emp_no'];//employee number
    $user_id = $_SESSION['user_id'];//user ID
    $image_id = NULL;
    $original = "images/original/".$filename;//our image
    $last_name =$_SESSION['last_name'];
    $path = "images/thumbnail/".$filename;

    $sql=mysql_query("INSERT INTO `webcam_clockin` 
        (`image_id`, `user_id`, `images`, `emp_no`, `last_name`) 
        VALUES ('$image_id', '$user_id','$path','$emp_no', '$last_name')");
        move_uploaded_file($original, $path);

    if(move_uploaded_file($filename, $original)){

        echo "The file ". $original.$filename. " has been uploaded, and your information has been added to the directory";
        echo "Thank You "; echo $userRow['username']; echo".\n";
    }
    else{
            echo "Sorry, there was a problem uploading your file.";
            echo "Error inserting entry data: ".mysql_error();
    ?>
        
        

我终于解决了将图像保存到数据库的问题.问题是phpmyadmin中的错误数据类型应该是longblob.

推荐阅读
围脖上的博博_771
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有