我目前正在實現照片快照功能,以允許用戶通過網絡攝像頭設置他們的個人資料照片。爲此,我使用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