Guest User

Untitled

a guest
Jul 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. $(document).ready(function(){
  2. $('#upload').click(function(){
  3.  
  4. var fd = new FormData();
  5. var files = $('#file')[0].files[0];
  6. fd.append('file',files);
  7.  
  8. // AJAX request
  9. $.ajax({
  10. url: 'clienttest.php',
  11. type: 'post',
  12. data: fd,
  13. contentType: false,
  14. processData: false,
  15. success: function(response){
  16. if(response != 0){
  17. // Show image preview
  18. $('#preview').html(" Process Started");
  19. }else{
  20. alert('file not uploaded');
  21. }
  22. }
  23. });
  24. });
  25. });
  26.  
  27. <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  28. <div class="modal-dialog">
  29. <div class="modal-content">
  30. <div class="modal-header">
  31. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  32. <h4 class="modal-title" id="myModalLabel">Load Secure Document</h4>
  33. </div>
  34. <div class="modal-body">
  35. <form method='post' action='' enctype="multipart/form-data">
  36. <label for="nametag">Name</label>
  37. <input type="text" name="nametag" size="20" />
  38.  
  39. Select file : <input type='file' name='file' id='file' class='form-control' ><br>
  40. <input type='button' class='btn btn-info' value='Upload' id='upload'>
  41. </form>
  42.  
  43. <!-- Preview-->
  44. <div id='preview'></div>
  45. </div>
  46. <div class="modal-body3">
  47. </div>
  48. <div class="modal-footer">
  49. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54.  
  55. // file name
  56. $filename = $_FILES['file']['name'];
  57.  
  58. // Location
  59. $location = $filename;
  60.  
  61. // file extension
  62. $file_extension = pathinfo($location, PATHINFO_EXTENSION);
  63. $file_extension = strtolower($file_extension);
  64.  
  65. // Valid image extensions
  66. $image_ext = array("jpg","png","jpeg","gif","pdf");
  67.  
  68. $response = 0;
  69. if(in_array($file_extension,$image_ext)){
  70. // Upload file
  71. if(move_uploaded_file($_FILES['file']['tmp_name'],$location)){
  72. $response = $location;
  73. }
  74. }
  75.  
  76. mail ('email@email.com','email of name',"name is ".$_POST['nametag']);
  77.  
  78. echo $response;
  79.  
  80. $(document).ready(function(){
  81. $('#upload').click(function(){
  82.  
  83. event.preventDefault();
  84. var form = $("#my-form")[0];
  85. var data = new FormData(form);
  86. // AJAX request
  87. $.ajax({
  88. url: 'clienttest.php',
  89. type: 'post',
  90. data: data,
  91. contentType: false,
  92. processData: false,
  93. success: function(response){
  94. if(response != 0){
  95. // Show image preview
  96. $('#preview').html(" Process Started");
  97. }else{
  98. alert('file not uploaded');
  99. }
  100. }
  101. });
  102. });
  103. });
Add Comment
Please, Sign In to add comment