PHP 7 Script to Take Selfie or Picture From Webcamera Using Javascript and Upload Image to Server and MySQL Database Automatically Full Project For Beginners

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments



<!DOCTYPE html>
    <title>WebCam jQuery and PHP script</title>
    <script src=""></script>
        #camera_wrapper, #show_saved_img{float:left; width: 650px;}
    <script type="text/javascript" src="scripts/webcam.js"></script>
            //give the php file path
            webcam.set_api_url( 'saveimage.php' );
            webcam.set_swf_url( 'scripts/webcam.swf' );
            webcam.set_quality( 100 ); // Image quality (1 - 100)
            webcam.set_shutter_sound( true ); // play shutter click sound
            var camera = $('#camera');
            camera.html(webcam.get_html(600, 460));
                //take snap
            //after taking snap call show image
            webcam.set_hook( 'onComplete', function(img){
                $('#show_saved_img').html('<img src="' + img + '">');
                //reset camera for next shot
    <h1>Capture photo with Web Camera - PHP Script</h1>
    <!-- camera screen -->
    <div id="camera_wrapper">
    <div id="camera"></div>
    <br />
    <button id="capture_btn">Capture</button>
    <!-- show captured image -->
    <div id="show_saved_img" ></div>


//set random name for the image, used time() for uniqueness
$filename =  time() . '.jpg';
$filepath = 'saved_images/';
//read the raw POST data and save the file with file_put_contents()
$result = file_put_contents( $filepath.$filename, file_get_contents('php://input') );
if (!$result) {
    print "ERROR: Failed to write data to $filename, check permissionsn";

echo $filepath.$filename;

Leave a Reply