2

im having a hard time saving the image captured from the webcam using the jquery webcam plugin. here's the code..

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

    });

i am using the 'save' mode. in the body part..

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

in the upload.php part..

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

i also tried the callback mode still doesnt work. it seems the blog itself has insufficient examples

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

[update]

finally got it working! i can capture the images. i dug up the source code of the page and added an onload eventlistener on my code :D

now my only problem is how to save the image. the blog doesn't clearly specify how. it just gave the codes

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

which is honestly i don't know what to do with it, unlike the php code he gave. should i put it in a link? or edit the onCapture part?

5
  • Which part is failing? Is it getting to the PHP code fine, or is the error occurring with how the PHP file is getting the data etc? Jul 4, 2011 at 10:50
  • javascript:webcam.capture();changeFilter();void(0); as suppose to save...look at the link Take a picture instantly
    – Val
    Jul 4, 2011 at 11:36
  • it doesn't display anything. @val the capture() function, I think it is only usable in the callback mode. like i said i am using the save mode. ill try later :) Jul 4, 2011 at 12:24
  • 1
    you must capture it first according to his documentation... then save it, just read thru it properly :) hope it works for u
    – Val
    Jul 4, 2011 at 12:35
  • finally got it working. now my only problem is how to save the captured image in the server :D Jul 4, 2011 at 16:17

1 Answer 1

3

You going to need to do a little PHP Here is a basic upload script, from the JPEGCam project

<?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";

?>
2
  • currently on another project but i guess this should be working :) gonna try it sooner Jul 26, 2011 at 20:03
  • any idea why I get a broken image?
    – jpganz18
    Nov 3, 2015 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.