I'm new to php and javascript...So I don't really know how to achieve my goal. Here I have 2 php files, first file :
<?php
<div class="col-sm-3">
<label class:>Nama :</label>
</div>
<div class="col-sm-9">
<input type="text" name="nama_tamu" id='nama_tamu' class="form-control" placeholder="Nama Lengkap">
</div>
<label>Foto Tamu</label>
<!-- form yang akan menempatkan jendela webcam untuk menampilkan layar webcam ya....-->
<p>
<script language="JavaScript" name="foto" id="foto">
document.write( webcam.get_html(320, 240) );
webcam.set_api_url( '../camera/saveImage.php' );
webcam.set_quality( 90 ); // JPEG quality (1 - 100)
webcam.set_shutter_sound( true ); // play shutter click sound
webcam.set_hook( 'onComplete', 'my_completion_handler' );
<!-- record gambar -->
function take_snapshot(){
webcam.freeze();
var x;
if (confirm("Simpan gambar?") == true) {
x = "Menyimpan gambar ...";
webcam.upload()
} else {
x = "Gambar tidak tersimpan.";
webcam.reset();
}
document.getElementById("upload_results").innerHTML = x;
}
function my_completion_handler(msg) {
// extract URL out of PHP output
if (msg.match(/(http\:\/\/\S+)/)) {
// show JPEG image in page
document.getElementById('upload_results').innerHTML ='Penyimpanan berhasil!';
// reset camera for another shot
webcam.reset();
}
else {
alert("PHP Error: " + msg);
}
}
</script>
</p>
<p>
<input type="button" class="btn btn-warning" value="Ambil Gambar" onclick="take_snapshot()">
echo $GLOBALS['$imagename'];
</p>
?>
and the second php file is like this :
<?php
session_start();
// untuk membangun koneksi ke database
include '../config/connect.php';
$imagename = $GLOBALS['nama_tamu'].date('YmdHis');
$newname="../camera/".$name.".jpg";
$file = file_put_contents( $newname, file_get_contents('php://input') );
if (!$file) {
print "ERROR: Gagal menyimpan $filename, cek permissions \n";
exit();
}
else
{
// menyimpan gambar ke database
$sql="Insert into entry(camera) values('$newname')";
$result=mysqli_query($con,$sql) or die("error sql connect");
$value=mysqli_insert_id($con);
$_SESSION["myvalue"]=$value;
}
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' . $newname;
print "$url\n";
?>
My goal here is I want to send nama_tamu (first php file) value to saveImage.php (second php file) buuut because saveImage.php is called withouth using POST or GET method, so I'm using GLOBALS variable there :
$imagename = $GLOBALS['nama_tamu'].date('YmdHis');
Unfortunaly it doesn't work, and I have no idea how to send this nama_tamu value to saveImage.php... Any idea...???
The second goal is in saveImage.php there is a variable called $imagename
. I want to send it's value back to the first php file and print it to the user like this :
echo $GLOBALS['$imagename'];
That doesn't work too...May be because GLOBALS only work for the same file not for different file....!
So any idea how to achieve my two goals here..??? Thanks in advance, I really appreciate your help... :)