首页 文章

jQuery网络摄像头插件 - 保存图像

提问于
浏览
2

我很难使用jquery网络摄像头插件保存从网络摄像头捕获的图像 . 这是代码..

$(document).ready(function(){
    $("#camera").webcam({
        width: 320,
        height: 240,
        mode: "save",
        swffile: "jscam.swf",   
    });

    });

我正在使用'保存'模式 . 在身体部分..

<div id="camera"></div>
<a href="javascript:webcam.save('upload.php');void(0);">capture</a>

在upload.php部分..

$str = file_get_contents("php://input");
file_put_contents("upload.jpg", pack("H*", $str));

我也试过回调模式仍然无法正常工作 . 博客本身似乎没有足够的例子

http://www.xarg.org/project/jquery-webcam-plugin/

[更新]

终于搞定了!我可以拍摄图像 . 我挖出了页面的源代码,并在我的代码上添加了一个onload eventlistener:D

现在我唯一的问题是 how to save the image . 博客没有明确说明如何 . 它只是给了代码

webcam.save('/upload.php');

老实说,我不知道该怎么做,不像他给的PHP代码 . 我应该 put it in a link ?还是 edit the onCapture part

1 回答

  • 3

    你需要做一点PHP这是一个来自JPEGCam项目的基本上传脚本

    <?php
    
    /* JPEGCam Test Script */
    /* Receives JPEG webcam submission and saves to local file. */
    /* Make sure your directory has permission to write files as your web server user! */
    
    $filename = date('YmdHis') . '.jpg';
    $result = file_put_contents( '/path/to/file/store/or/site/' . $filename, 
          file_get_contents('php://input') );
    if (!$result) {
        print "ERROR: Failed to write data to $filename, check permissions\n";
        exit();
    }
    
    $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' 
         . $filename;
    print "$url\n";
    
    ?>
    

相关问题