我目前正在实现照片快照功能,以允许用户通过网络摄像头设置他们的个人资料照片。为此,我使用 jQuery Webcam Plugin .
出现问题的原因是我想让用户单击“拍照”并将快照保存到服务器的适当位置以供用户图像 API 检索。
看起来这应该很容易做到,但由于某种原因我遇到了问题。当按下我的按钮时,照片捕捉正常,但保存没有正确执行,因为我收到错误 error: No save mode compiled in.
注意:我的保存 URL 包含一个 hash
变量,如 ?hash=XYZ123
。这就是图像在 PHP 文件中的命名方式。
我试图从 url 中删除 hash
和 ref
变量,认为这可能导致图像数据以某种方式丢失/被忽略,但没有产生任何结果区别。谁能看到我在这里做错了什么?我很确定我遵循了文档以及位于此处的其他几篇文章,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.
最佳答案
这是你的错误:
swffile: "/webcam/jscam_canvas_only.swf",
应该是:
swffile: "js/jscam.swf",
引自 plugin webpage :
Points to the swf file of the Flash movie, which provides the webcam API. There are two swf files provided via the download archive: jscam.swf, which provides the full API and jscam_canvas_only.swf which have no embedded JPEG library (I embedded an adjusted JPGEncoder of the AS 3 corelib). Thereby, the file is only one third as large as the original.
关于php - jQuery 网络摄像头 : Save mode results in: '' error: No save mode compiled in.“,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7574223/