我目前正在实现照片快照功能,以允许用户通过网络摄像头设置他们的个人资料照片。为此,我使用jQuery Webcam Plugin。jQuery摄像头:保存模式导致:''错误:没有保存模式编译。“
在问题出现我想有用户点击“拍摄照片”,并在适当的位置保存到服务器的快照由用户图像API来检索。
看来这应该很容易做到,但由于某种原因,我遇到了问题,当按下按钮时,照片拍摄会正常进行,但由于我收到错误信息error: No save mode compiled in.
注意:我的保存URL包含一个hash
变量,如?hash=XYZ123
。这就是图像在PHP文件中的命名方式。
我试图从url中删除hash
和ref
变量,认为这可能导致图像数据以某种方式丢失/忽略,但这没有什么区别。任何人都可以看到我在这里做错了吗?我很确定我遵循了SO,like this one上的文档以及其他几个帖子。
截图
HTML
<div id="camera"></div> <!-- WebCam Live Display -->
<div id="wcStatus"></div> <!-- Debug Text Display -->
<button onclick="showWebcam();">Use Webcam Instead</button>
<!--This button is normally hidden until camera initialized, but for sake for demo-->
<button onclick="saveWebCam('XYZ123', '66');">Take a picture!</button>
JS
function showWebcam(){
$("#camera").webcam({
width: 320,
height: 240,
mode: "save",
swffile: "/webcam/jscam_canvas_only.swf",
debug: function(type, string) {
$('#wcStatus').append(type + ": " + string + '<br /><br />');
}
});
}
function saveWebCam(hash, id){
var url = '/accountFiles/userImages/saveFromWebCam.php?hash=' + hash + '&ref=' + randomString(30);
$('#wcStatus').append('Capturing: ' + url + '<br /><br />');
webcam.capture();
webcam.save(url);
}
PHP(saveFromWebCam.php)
<?php
$destFile=$_REQUEST['hash'].'.jpg';
$str = file_get_contents('php://input');
file_put_contents($destFile, pack("H*", $str));
?>
调试输出
notify: Camera started
Capturing: /accountFiles/userImages/saveFromWebCam.php
notify: Capturing started.
notify: Capturing finished.
error: No save mode compiled in.
你确定你正在使用的插件的最新版本?正如我在github上看到的那样,你提到的错误信息可能来自actionscript文件,但该行被推荐出来。如果检查失败,尝试检查jquerycam插件的其他forks https://github.com/infusion/jQuery-webcam/network/members(尝试例如lalop或nedforce分叉)。 – WTK
感谢您的回复。我明确下载了最新版本(不止一次)。 – Dutchie432