Using input type button that can passing value to model with webcam.js in yii2

270 Views Asked by At

I am setting up my web application by implementing webcam.js using yii2 advance. but I can't figure out to passing the value because I am used to uploading the image by using

<?= $form->field($model, 'image')->fileInput(['accept' => 'image/*','class'=>'step3'])->label(false) ?> 

the code that I want to be implemented is:

<input type=button value="Take Snapshot" onClick="captureimage()".

My reference: http://codingbin.com/capture-webcam-image-with-php-and-jquery/

I already succeed to run the webcam to capture a selfie, but I don't know how to pass the value jpg to the controller or database using yii2. The reference link only gives how to save using regular PHP not in yii2. I want the syntax also in yii2 so I am more easy to implement to my system

//view
<div id="webcam"></div>
<div id="results"></div>
  <input type=button value="Take Snapshot" onClick="captureimage()">
//javascript
<script language="JavaScript">
        Webcam.set({
            width: 300,
            height: 200,
            image_format: 'jpeg',
            jpeg_quality: 90
        });
        Webcam.attach( '#webcam' );
        function captureimage() {
            // take snapshot and get image data
            Webcam.snap( function(data_uri) {
                // display results in page

//script                 
Webcam.upload( data_uri, '/frontend/controllers/ApplyController.php', function(code, text) {
                    document.getElementById('results').innerHTML = 
                    '<h2>Uploaded image:</h2>' + 
                    '<img src="'+text+'"/>';
                } );    
            } );
        }
    </script>

I expected I can capture the picture and store it into the database through the model.

0

There are 0 best solutions below