0

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.

Phoenix
  • 3,996
  • 4
  • 29
  • 40
dave
  • 1
  • 2
  • there isnt anything new, it uses javascript to upload the captured image, you just need to setup the server-side code including the model and controller action as described in this article https://yii2-framework.readthedocs.io/en/stable/guide/input-file-upload/ – Muhammad Omer Aslam Oct 11 '19 at 11:06
  • @MuhammadOmerAslam but from the documentation how can i add form field into input button? since i need a button to run the function to upload. Thank you for responding. – dave Oct 14 '19 at 03:50

0 Answers0