Advertisement
Guest User

Untitled

a guest
May 24th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <-- you should use Bootstrap3 and jQuerry 2.1.3 or up --!>
  2.  
  3. <div class="row">
  4. <form action="javascript:;">
  5. <input id="lefile" type="file" style="display:none">
  6. <div class="col-xs-8 form-inline">
  7. <input id="filepath" class="form-control" type="text">
  8. <a class="btn btn-default" onclick="$('input[id=lefile]').click();">Browse</a>
  9. <input type="submit" class="btn btn-primary" id="update" value="POST" />
  10. </div>
  11. </form>
  12. </div>
  13.  
  14. <script>
  15. $('input[id=lefile]').change(function() {
  16. $('#filepath').val($(this).val().replace(/(c:\\)*fakepath\\/i, ''));
  17. });
  18.  
  19. $(function(){
  20. $("#update").bind("click", function(){
  21. // loading message
  22.  
  23. var fd = new FormData();
  24.  
  25. if ( $("#lefile").val() !== '' ) {
  26. fd.append( "file", $("#lefile").prop("files")[0] );
  27. }
  28.  
  29. var postData = {
  30. type : "POST",
  31. dataType : "text",
  32. data : fd,
  33. processData : false,
  34. contentType : false
  35. };
  36.  
  37. $.ajax( "./upload.php", postData ).done(function( text ){
  38. // success message
  39. });
  40.  
  41. });
  42. });
  43. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement