Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function(){
- $('#upload').click(function(){
- var fd = new FormData();
- var files = $('#file')[0].files[0];
- fd.append('file',files);
- // AJAX request
- $.ajax({
- url: 'clienttest.php',
- type: 'post',
- data: fd,
- contentType: false,
- processData: false,
- success: function(response){
- if(response != 0){
- // Show image preview
- $('#preview').html(" Process Started");
- }else{
- alert('file not uploaded');
- }
- }
- });
- });
- });
- <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
- <div class="modal-dialog">
- <div class="modal-content">
- <div class="modal-header">
- <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
- <h4 class="modal-title" id="myModalLabel">Load Secure Document</h4>
- </div>
- <div class="modal-body">
- <form method='post' action='' enctype="multipart/form-data">
- <label for="nametag">Name</label>
- <input type="text" name="nametag" size="20" />
- Select file : <input type='file' name='file' id='file' class='form-control' ><br>
- <input type='button' class='btn btn-info' value='Upload' id='upload'>
- </form>
- <!-- Preview-->
- <div id='preview'></div>
- </div>
- <div class="modal-body3">
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
- </div>
- </div>
- </div>
- </div>
- // file name
- $filename = $_FILES['file']['name'];
- // Location
- $location = $filename;
- // file extension
- $file_extension = pathinfo($location, PATHINFO_EXTENSION);
- $file_extension = strtolower($file_extension);
- // Valid image extensions
- $image_ext = array("jpg","png","jpeg","gif","pdf");
- $response = 0;
- if(in_array($file_extension,$image_ext)){
- // Upload file
- if(move_uploaded_file($_FILES['file']['tmp_name'],$location)){
- $response = $location;
- }
- }
- mail ('email@email.com','email of name',"name is ".$_POST['nametag']);
- echo $response;
- $(document).ready(function(){
- $('#upload').click(function(){
- event.preventDefault();
- var form = $("#my-form")[0];
- var data = new FormData(form);
- // AJAX request
- $.ajax({
- url: 'clienttest.php',
- type: 'post',
- data: data,
- contentType: false,
- processData: false,
- success: function(response){
- if(response != 0){
- // Show image preview
- $('#preview').html(" Process Started");
- }else{
- alert('file not uploaded');
- }
- }
- });
- });
- });
Add Comment
Please, Sign In to add comment