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 :)
1473
Ellyx Christian
0
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
  • Sep 8, 2016
  • 0 suka, 0 tidak suka
0
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
  1.  
  2. <?php
  3. require_once "config.php";
  4. $q = mysqli_query($con,"SELECT MAX(no) FROM tbl_datang");
  5. $row = mysqli_fetch_array($q);
  6. $no = '';
  7. if($row['0'] == "") {
  8. $no .= '1';
  9. } else {
  10. $angka = $row['0'];
  11. $angka ++;
  12. $no .= $angka;
  13.  
  14. }
  15. ?>
  16. <!doctype html>
  17. <section id="content" class="body">
  18. <form class="form" action="proses.php" method="post" enctype="multipart/form-data">
  19. <!doctype html>
  20. <html>
  21. <head>
  22.  
  23. <h2>Absensi Online</h2>
  24. <p>&nbsp;</p>
  25. <table><tr><td valign=top>
  26. <h1> Berbasis Web dengan Menggunakan Webcam </h1>
  27. <h3>PT PLTU TARAHAN</h3>
  28.  
  29. <!-- First, include the JPEGCam JavaScript Library -->
  30. <script type="text/javascript" src="webcam.js"></script>
  31.  
  32. <!-- Configure a few settings -->
  33. <script language="JavaScript">
  34. webcam.set_api_url( 'test.php' );
  35. webcam.set_quality( 90 ); // JPEG quality (1 - 100)
  36. webcam.set_shutter_sound( true ); // play shutter click sound
  37. </script>
  38.  
  39. <!-- Next, write the movie to the page at 320x240 -->
  40. <script language="JavaScript">
  41. document.write( webcam.get_html(320, 240) );
  42. </script>
  43.  
  44. <!-- Some buttons for controlling things -->
  45. <br/><form>
  46. <input type=button value="Configure..." onClick="webcam.configure()">
  47. &nbsp;&nbsp;
  48. <input type=button value="Take Snapshot" onClick="take_snapshot()">
  49. </form>
  50.  
  51. <!-- Code to handle the server response (see test.php) -->
  52. <script language="JavaScript">
  53. webcam.set_hook( 'onComplete', 'my_completion_handler' );
  54.  
  55. function take_snapshot() {
  56. // take snapshot and upload to server
  57. document.getElementById('upload_results').innerHTML = '<h1>Uploading...</h1>';
  58. webcam.snap();
  59. }
  60.  
  61. function my_completion_handler(msg) {
  62. // extract URL out of PHP output
  63. if (msg.match(/(http\:\/\/\S+)/)) {
  64. var image_url = RegExp.$1;
  65. // show JPEG image in page
  66. document.getElementById('upload_results').innerHTML =
  67. '<h1>Upload Successful!</h1>' +
  68. '<h3>JPEG URL: ' + image_url + '</h3>' +
  69. '<img src="' + image_url + '">';
  70.  
  71. // reset camera for another shot
  72. webcam.reset();
  73. }
  74. else alert("PHP Error: " + msg);
  75. }
  76. </script>
  77.  
  78.  
  79. </td><td width=50><td><?php echo $foto_datang;?></td></td><td valign=top>
  80. <div id="upload_results" style="background-color:#eee;"></div>
  81. </td></tr></table>
  82.  
  83.  
  84. <!-- tambahkan jquery dan jquery ui -->
  85. <script type="text/javascript" src="js/jquery-1.9.0.js"></script>
  86. <script type="text/javascript" src="js/jquery-ui.min.js"></script>
  87. <link type="text/css" rel="stylesheet" href="js/jquery-ui-1.10.4.custom.min.css"/>
  88. </head>
  89. <body>
  90.  
  91. <li>
  92. <label>No </label>
  93. <input type="text" name="no" size="15" value="<?php echo $no; ?>" readonly="readonly"/>
  94. </li>
  95. <li>
  96. <label>ID</label>
  97. <input type="text" name="id" size="20" class="form-control" id="id" />
  98. </li>
  99. <li>
  100. <label>Nama Lengkap</label>
  101. <input type="text" name="nama" id="nama" readonly="readonly"/>
  102. </li>
  103. <li>
  104. <label>Tanggal*</label>
  105. <input type="date" name="tanggal"size="30" value="<?php date_default_timezone_set('Asia/Jakarta');
  106. $tanggal= mktime(date("m"),date("d"),date("Y"));
  107. $tglsekarang = date("Y-m-d", $tanggal);
  108. echo $tglsekarang;?>" readonly=/>
  109. <li>
  110. <label>Jam Datang*</label>
  111. <input name="jam_datang" type="text" id="jam_datang" value="<?php $today = date("H:i:s"); echo $today;?>" readonly/>
  112. </li>
  113. <li>
  114. <label>Foto Datang*</label>
  115. <input name="foto_datang" type="text" id="foto_datang" size="60" required />
  116. </li>
  117.  
  118. <script>
  119. $(function() {
  120. $( "#id" ).autocomplete({
  121. source: "get_product.php",
  122. minLength: 2,
  123. select: function( event, ui ) {
  124. $('#nama').val(ui.item.nama);
  125. }
  126. });
  127. });
  128. </script>
  129. <label></label>
  130. </li>
  131.  
  132.  
  133.  
  134. <p>&nbsp;</p>
  135. <label></label>
  136. <div align="right">
  137. <p align="left">
  138. <input name="absen" type="submit" id="absen" value="ABSEN" />
  139. </p>
  140. <p>&nbsp;</p>
  141. <p>
  142. <label></label>
  143. <p align="left">
  144.  
  145. <label></label>
  146. <div align="left"></li>
  147. </p>
  148. </div>
  149. </div>
  150. </form>
  151. </section>
  152. <span class="form">
  153. <label></label>
  154. </span>
  155. </body>
  156. </html>
  157.  
  158.  

kemudian ini script test.php
  1. <?php
  2.  
  3. /* JPEGCam Test Script */
  4. /* Receives JPEG webcam submission and saves to local file. */
  5. /* Make sure your directory has permission to write files as your web server user! */
  6.  
  7. $filename = date('YmdHis') . '.jpg';
  8. $result = file_put_contents( $filename, file_get_contents('php://input') );
  9. if (!$result) {
  10. print "ERROR: Failed to write data to $filename, check permissions\n";
  11. exit();
  12. }
  13.  
  14. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' . $filename;
  15. print "$url\n";
  16.  
  17. ?>
  18.  

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

$no = $_POST['no'];
$id = $_POST['id'];
$nama = $_POST['nama'];
$tanggal = $_POST['tanggal'];
$jam_datang = $_POST['jam_datang'];
$foto_datang = $_POST['foto_datang'];

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

$status = 'false';
$_SESSION['pass'] = $pass;
$_SESSION['no'] = $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
  • Sep 11, 2016
  • 0 suka, 0 tidak suka
4951
Please login to answer!
/sangkep/answer/add-json/nogzip/1
/sangkep/answer/send-notification
User Paling Aktif Bulan Lalu

Rey Paksi Manggala

Rey Paksi Manggala

Point Bulan Lalu: 6