Advertisement
Ranga14

Gotpix.com JS/JQuery Profile BG Upload

Aug 14th, 2013
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2.     $(function() {
  3.         $("#uploadFile").click(function(e) {
  4.             // User clicks form input field and default click action is prevented
  5.             $("#fileUploadField").click();
  6.             e.preventDefault();
  7.            
  8.             // Once a user clicks they will fire the form action
  9.             $("#fileUploadField").change(function() {
  10.                
  11.                 // iframe HTML
  12.                 var iframe = $('<iframe name="postiframe" id="postiframe" target="postiframe" style="display: none;" /></iframe>');
  13.                
  14.                 // Append said iframe
  15.                 $("body").append(iframe);
  16.                
  17.                 // Let's submit the form to process on the backend
  18.                 var form = $('#UploadForm');
  19.                 form.attr("action", "./includes/objects/profile_bg_upload.php");
  20.                 form.attr("method", "post");
  21.                 form.attr("enctype", "multipart/form-data");
  22.                 form.attr("encoding", "multipart/form-data");
  23.                 form.attr("target", "postiframe");
  24.                 form.attr("hidden", $("input[name=userID]").val());
  25.                 form.attr("file", $(this).val());
  26.                 form.submit();
  27.                
  28.                 // Load new bg image on the fly
  29.                 $("#postiframe").load(function () {
  30.                     iframeContents = $("#postiframe")[0].contentWindow.document.body.innerHTML;
  31.                     $("#tempBox").html(iframeContents);
  32.                 });
  33.                
  34.                 return false;
  35.             });
  36.            
  37.             $("#UploadForm").submit(function(){
  38.                 location.reload()          
  39.             });
  40.            
  41.         });    
  42.     });
  43. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement