0

made a websitem, or trying to, where you can take a picture with your webcam and then upload it to the server, but ive found some inspiration in a guy that uses PHP and i wanna avoid it as much as posible. so what i have now in my .html for uploading is the picture is:

 // Upload image to sever 
        document.getElementById("upload").addEventListener("click", function(){
            var dataUrl = canvas.toDataURL("images/", 0.85);
            $("#uploading").show();
            $.ajax({
              type: "POST",
              url: "html5-webcam-save.php",
              data: { 
                imgBase64: dataUrl,
                 //user: "Joe"                
              } 

and then the reference(html5-webcam-save.php):

<?php

$rawData = $_POST['imgBase64'];
$filteredData = explode(',', $rawData);
$unencoded = base64_decode($filteredData[1]);

 $datime = date("Y-m-d-H.i.s", time() ) ; # - 3600*7

//$userid  = $_POST['userid'] ;

// name & save the image file 
$fp = fopen('images/'.$datime.'-'.$userid.'.jpg', 'w');
fwrite($fp, $unencoded);
fclose($fp);

so my question, anyone now how to upload it to the server or just the "images" folder in the root of the site, without the need for PHP.

  • to be honest, the reason i dont want the PHP is because i simply cant get it to work properly on the server side, and iam lost when it comes to php. So can this be done with for instance C#/Javascript?

1 Answers1

1

"..without the need for PHP"

You can't. You need a server side language to receive the data from raw http, convert it back from base64 text to image and then write it to disc. It could be PHP, c#, nodejs javascript, but there will always be a server side controller handling all this. You can't access server file system from client javascript for obvious security reasons.

Oscar
  • 13,594
  • 8
  • 47
  • 75