Advertisement
Guest User

Untitled

a guest
Feb 10th, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    $('#image').change(function(e) {                                                                                                                  
  2.                                                                                                                                                        
  3.       var file = e.target.files[0];                                                                                                                    
  4.                                                                                                                                                        
  5.       if (file.type == '') {                                                                                                                          
  6.         admin.status('Unknown file type');                                                                                                            
  7.         return true;                                                                                                                                  
  8.       }                                                                                                                                                
  9.                                                                                                                                                        
  10.       if (!file.type.match('image.*')) {                                                                                                              
  11.         admin.status('Your file must be a proper image');                                                                                              
  12.         return true;                                                                                                                                  
  13.       }                                                                                                                                                
  14.                                                                                                                                                        
  15.       var reader = new FileReader();                                                                                                                  
  16.       var content = '';                                                                                                                                
  17.                                                                                                                                                        
  18.       reader.onload = (function(theFile) {                                                                                                            
  19.                                                                                                                                                        
  20.         return function(e) {                                                                                                                          
  21.                                                                                                                                                        
  22.           admin.notify('Uploading Image.. 0%');                                                                                                        
  23.                                                                                                                                                        
  24.           var xhr = new XMLHttpRequest();                                                                                                              
  25.           xhr.open('POST', '/ajx/image.php', true);                                                                                                    
  26.                                                                                                                                                        
  27.           xhr.upload.onprogress = function(e) {                                                                                                        
  28.             var progress = Math.round((e.loaded / e.total) * 100) + '%';                                                                              
  29.             $('.notify').html('Uploading Image.. ' + progress);                                                                                        
  30.           };                                                                                                                                          
  31.                                                                                                                                                        
  32.           xhr.upload.onloadend = function(response) {                                                                                                  
  33.             admin.status('Upload Complete');                                                                                                          
  34.             console.log(e);                                                                                                                            
  35.             console.log(xhr.status);                                                                                                                  
  36.             console.log(xhr.response);                                                                                                                
  37.           };                                                                                                                                          
  38.                                                                                                                                                        
  39.           xhr.send(e.target.result);                                                                                                                  
  40.                                                                                                                                                        
  41.         };                                                                                                                                            
  42.                                                                                                                                                        
  43.       })(file);      
  44.  
  45.     reader.readAsBinaryString(file);
  46.  
  47.     });
  48. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement