I have a webcam script inside a form and I need it when I take the photo, it saves the file with the name entered in the input on the same form.
This is the part of the webcam code where it sends a php file to save the photo
var nome = document.getElementById("nome").value;
document.getElementById("save").addEventListener("click", function() {
$.post('library/salvar.php?nome='.nome, {imagem:canvas.toDataURL()}, function(data){
},'json');
});
PHP file that receives the photo and saves
function base64_to_jpeg( $base64_string, $output_file ) {
$ifp = fopen( $output_file, "wb" );
fwrite( $ifp, base64_decode( $base64_string) );
fclose( $ifp );
return( $output_file );
}
$imagem = str_replace('data:image/png;base64,','',$_POST['imagem']);
base64_to_jpeg($imagem, "../assets/fotos/".$_GET['nome'].".png");
echo json_encode(array('imagem' => 1));
But he is not saving, I believe that in this passage I am doing wrong:
'library/salvar.php?nome='.nome,
Please help me !!!
SOLVED! Replace line
$.post('library/salvar.php?nome='.nome, {imagem:canvas.toDataURL()}, function(data){
By
$.post('library/salvar.php?nome='+$("input[name=nome]").val(), {imagem:canvas.toDataURL()}, function(data){