1
I have an HTML5 application that captures a webcam image through the browser that I need to capture and record to the database as a binary.
On the server side, in PHP, I have:
$directory = $img;
$element_img = base64_encode(file_get_contents($directory));
And the process of capturing the client, with Javascript, takes place through the onClick event of a button, which after captured sends it to another window that I open in the browser:
function btnCaptura() {
var img = App.canvas.toDataURL("image/png");
window.open(img, "_blank", "menubar=0,titlebar=0,toolbar=0,width=" + App.canvas.width + ",height=" + App.canvas.height);
}
And although it works, that is, the captured image is sent to the open window, I need to send this image to PHP so that it can be saved in the database, but I’m not getting it.
Note: If it is possible to do everything in the same window, without opening a new one, just showing a warning that the image was captured successfully, it would be better.
Test what I told you in the answer and return if you have any problems.
– HiHello
I can put the code of your save function inside my btnCaptura function thus: Function btnCaptura() { var img = App.canvas.toDataURL("image/png"); window.open(img, "_self", "menubar=0,Titlebar=0,Toolbar=0,width=" + App.canvas.width + ",height=" + App.canvas.height); sessionStorage.setItem('image', img); /* if it is convenient to keep the data after the user closes the browser, create a localStorage instead of a sessionStorage */ Alert("Successfully saved"); Location.Reload(); }
– celso Roberto
What are you going to use open() for? No need, in your case.
– HiHello
Look at my answer.
– HiHello
commented the line //window.open(img...... as your example captured the content of the img variable that is in javascript, in php it looked like this: $img = "<script> sessionStorage.getItem('image');</script>"; var_dump ($img); $directory = $img; $element = base64_encode(file_get_contents($directory)); echo '<img src="data:image/png;Base64,'. $element. ' "/>'; giving error->>>>string(51) "" Warning: file_get_contents(): failed to open stream: Invalid argument
– celso Roberto
To pass url as filename you must have allow_url_fopen in php.ini enabled. See if this is it.
– HiHello
Directive; Local Value; Master Value; allow_url_fopen; On; On;
– celso Roberto