Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. <script src="webcam.js"></script> <!--source code script from github for webcam config-->
  2.  
  3. <div id="my_camera" style="width:320px; height:240px;"></div>
  4. <div id="my_result"></div>
  5.  
  6. <script type=text/javascript>
  7. Webcam.attach( '#my_camera' );
  8.  
  9. function take_snapshot() {
  10. Webcam.snap( function(data_uri) {
  11. document.getElementById('my_result').innerHTML = '<img src="'+data_uri+'"/>';
  12. } );
  13. }
  14. </script>
  15.  
  16. <a href="javascript:void(take_snapshot())">Take Snapshot</a>
  17.  
  18. <?php
  19. session_start();
  20. include_once'database.php';
  21. $uid = $_SESSION['u_id'];
  22.  
  23. if (isset($_POST['submit'])){
  24. $file = $_FILES['file'];
  25.  
  26. $fileName = $_FILES['file']['name'];
  27. $fileTmpName = $_FILES['file']['tmp_name'];
  28. $fileSize = $_FILES['file']['size'];
  29. $fileError = $_FILES['file']['error'];
  30. $fileType = $_FILES['file']['type'];
  31.  
  32. $fileExt = explode('.', $fileName);
  33. $fileActualExt = strtolower(end($fileExt));
  34.  
  35. $allowed = array('jpg', 'jpeg', 'png');
  36. //check if ang uploaded file allowed i upload//
  37. if (in_array($fileActualExt, $allowed)){
  38. if ($fileError == 0){
  39. if ($fileSize < 1000000){
  40. $fileNameNew = "profile".$uid.".".$fileActualExt;
  41. $fileDestination = 'uploads/'.$fileNameNew;
  42. move_uploaded_file($fileTmpName, $fileDestination);
  43. $sql = "UPDATE profileimg SET status=0 WHERE userID ='$uid';";
  44. $result = mysqli_query($conn, $sql);
  45. header("location:../pages/userpage.php");
  46. }
  47. else {
  48. echo "Your file is too big";
  49. }
  50. } else {
  51. echo "There was an error uploading you file!";
  52. }
  53. } else {
  54. echo "You cannot upload files of this type";
  55. }
  56.  
  57. }
  58.  
  59. Webcam.upload( data_uri, 'myscript.php', function(code, text) {
  60. // Upload complete!
  61. // 'code' will be the HTTP response code from the server, e.g. 200
  62. // 'text' will be the raw response content
  63. } );
  64.  
  65. } );
  66.  
  67. move_uploaded_file($_FILES['webcam']['tmp_name'], 'webcam.jpg');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement