Gan, nanya dong misalnya kita buat webcam di php, kita foto kan terus hasil fotonya udah nampil.
Pertanyaannya adalah?--> kalo kita mau nyimpen fotonya di database berdasarkan id yang kita input gimana ya? Terimakasih sebelumnya.Tolong bantu yaaa :)
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Sep 8, 2016 · 0 Suka · 0 Tidak Suka
hi novita,
agak sulit menjawabnya, tergantung dari form yang kamu buat. Bisa post potongan kode yang sudah kamu buat?

Mungkin bisa membantu: http://www.myphptutorials.com/tutorials/20/upload-gambar-dengan-php
0
Loading...
novita giovalda · Sep 11, 2016 · 0 Suka · 0 Tidak Suka
jadi gini kak, kan aku lagi buat absensi online melalui webcam, nah setiap kita absen kan foto duluu, setelah selesai foto maka akan tampil selanjutnya kta menginputkan id autocomplete beserta id, nama, tanggal dan jam datang berserta foto datangnya tersebut. nah gimana caranya agar foto tersebut masuk kedalam database berdasarkan data yang telah diinput. berikut ini kodingnya :
ini koding dari form datang.php

<?php
require_once "config.php";
	$q = mysqli_query($con,"SELECT MAX(no) FROM tbl_datang");
$row = mysqli_fetch_array($q);
$no = '';
if($row['0'] == "") {
	$no .= '1';
} else {
	$angka = $row['0'];
	$angka ++;
	$no .= $angka;
	
}
?>	
<!doctype html>
	<section id="content" class="body">
 		<form class="form" action="proses.php" method="post" enctype="multipart/form-data">
		 <!doctype html>
    <html>
    	<head>
		 
 		    <h2>Absensi Online</h2>
 		    <p>&nbsp;</p>
			<table><tr><td valign=top>
	<h1> Berbasis Web dengan Menggunakan Webcam </h1>
	<h3>PT PLTU TARAHAN</h3>
	
	<!-- First, include the JPEGCam JavaScript Library -->
	<script type="text/javascript" src="webcam.js"></script>
	
	<!-- Configure a few settings -->
	<script language="JavaScript">
		webcam.set_api_url( 'test.php' );
		webcam.set_quality( 90 ); // JPEG quality (1 - 100)
		webcam.set_shutter_sound( true ); // play shutter click sound
	</script>
	
	<!-- Next, write the movie to the page at 320x240 -->
	<script language="JavaScript">
		document.write( webcam.get_html(320, 240) );
	</script>
	
	<!-- Some buttons for controlling things -->
	<br/><form>
		<input type=button value="Configure..." onClick="webcam.configure()">
		&nbsp;&nbsp;
		<input type=button value="Take Snapshot" onClick="take_snapshot()">
	</form>
	
	<!-- Code to handle the server response (see test.php) -->
	<script language="JavaScript">
		webcam.set_hook( 'onComplete', 'my_completion_handler' );
		
		function take_snapshot() {
			// take snapshot and upload to server
			document.getElementById('upload_results').innerHTML = '<h1>Uploading...</h1>';
			webcam.snap();
		}
		
		function my_completion_handler(msg) {
			// extract URL out of PHP output
			if (msg.match(/(http\:\/\/\S+)/)) {
				var image_url = RegExp.$1;
				// show JPEG image in page
				document.getElementById('upload_results').innerHTML = 
					'<h1>Upload Successful!</h1>' + 
					'<h3>JPEG URL: ' + image_url + '</h3>' + 
					'<img src="' + image_url + '">';
				
				// reset camera for another shot
				webcam.reset();
			}
			else alert("PHP Error: " + msg);
		}
	</script>
	
	
	</td><td width=50><td><?php echo $foto_datang;?></td></td><td valign=top>
		<div id="upload_results" style="background-color:#eee;"></div>
	</td></tr></table>
	
	 
	 <!-- tambahkan jquery dan jquery ui -->
    		<script type="text/javascript" src="js/jquery-1.9.0.js"></script>
    		<script type="text/javascript" src="js/jquery-ui.min.js"></script>
    		<link type="text/css" rel="stylesheet" href="js/jquery-ui-1.10.4.custom.min.css"/>
    	</head>
    	<body>
    		
 		    <li>
            <label>No </label>
            <input type="text" name="no" size="15" value="<?php  echo $no; ?>" readonly="readonly"/>
</li>
		  <li>
		    <label>ID</label>
		    <input type="text" name="id" size="20" class="form-control" id="id"  />
		  </li>
		  <li>
		 			<label>Nama Lengkap</label>
					 <input type="text" name="nama" id="nama" readonly="readonly"/>
		  </li>
 		  <li>
 		            <label>Tanggal*</label>
            <input type="date" name="tanggal"size="30" value="<?php date_default_timezone_set('Asia/Jakarta');
$tanggal= mktime(date("m"),date("d"),date("Y"));
$tglsekarang = date("Y-m-d", $tanggal);
echo $tglsekarang;?>" readonly=/>
 		  <li>
		 		  <label>Jam Datang*</label>
		 		  <input name="jam_datang" type="text"  id="jam_datang" value="<?php $today = date("H:i:s"); echo $today;?>" readonly/>
 		  </li>
		 		<li>
		 			<label>Foto Datang*</label>
		 		    <input name="foto_datang" type="text" id="foto_datang" size="60"  required />
		 		</li>
		
    		<script>
        $(function() {
            $( "#id" ).autocomplete({
                source: "get_product.php",
                minLength: 2,
                select: function( event, ui ) {
    		$('#nama').val(ui.item.nama);
                }
            });
        });
    </script>
		 			<label></label>
		 		</li>
		
   
				
		 		<p>&nbsp;</p>
                <label></label>
          <div align="right">
            <p align="left">
              <input name="absen" type="submit" id="absen" value="ABSEN"  />
            </p>
            <p>&nbsp;</p>
            <p>
              <label></label>            
            <p align="left">

            <label></label>            
            <div align="left"></li>
            </p>
          </div> 
		  </div>
 		</form>
 	</section>
    <span class="form">
    <label></label>
</span>
 </body>
    </html>


kemudian ini script test.php
<?php

/* JPEGCam Test Script */
/* Receives JPEG webcam submission and saves to local file. */
/* Make sure your directory has permission to write files as your web server user! */

$filename = date('YmdHis') . '.jpg';
$result = file_put_contents( $filename, file_get_contents('php://input') );
if (!$result) {
	print "ERROR: Failed to write data to $filename, check permissions\n";
	exit();
}

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' . $filename;
print "$url\n";

?>

berikut ini script prosesnya proses.php
<?php
session_start();
include_once "config.php";

$no = $_POST;
$id = $_POST;
$nama = $_POST;
$tanggal = $_POST;
$jam_datang = $_POST;
$foto_datang = $_POST;

$number = range(0,9);
shuffle($number);
$getNumber = array_rand($number,6);
$pass = '';
foreach($getNumber as $n) {
$pass .= $n;
}

$status = 'false';
$_SESSION = $pass;
$_SESSION = $no;


$q = mysqli_query($con,"INSERT INTO tbl_datang VALUES('".$no."','".$id."','".$nama."','".$tanggal."','".$jam_datang."','".$foto_datang."')");
if($q) {
header('location: index.php?page=daftar&no='.$no);
}


?>


terimakasih kak sebelumnya