jQuery webcam plugin - saving image

18,777

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

?>
Share:
18,777
kapitanluffy
Author by

kapitanluffy

Updated on June 04, 2022

Comments

  • kapitanluffy
    kapitanluffy almost 2 years

    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?