Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. File Upload in IE

File Upload in IE

Scheduled Pinned Locked Moved JavaScript
questiondatabase
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    ziggyfish
    wrote on last edited by
    #1

    Hi, In firefox, and chrome, I have a progress bar when someone uploads a file, however the same code doesn't work in IE (surprise surprise), it fails on:

    var file = this.files[0];

    My question is how do I do the equivalent for IE? Pointing me to the documentation would best. code is:

    function uploadImage(){
    $('#percent').progressbar({
    value: 0
    });
    $( "#dialog" ).dialog({
    resizable: false,
    height:150,
    modal: true,
    buttons: {
    Cancel: function() {
    if (xhr){
    xhr.abort();
    xhr = null;
    }
    $( this ).dialog( "close" );
    }
    }
    });
    document.getElementById('photo').addEventListener('change', function(e) {
    var file = this.files[0];
    var formdata = new FormData();
    formdata.append('file', file);
    xhr = new XMLHttpRequest();
    xhr.file = file;
    xhr.addEventListener('progress', function(e) {
    var done = e.position || e.loaded, total = e.totalSize || e.total;
    $('#percent').progressbar('value', (Math.floor(done/total*1000)/10));
    }, false);
    if ( xhr.upload ) {
    xhr.upload.onprogress = function(e) {
    var done = e.position || e.loaded, total = e.totalSize || e.total;
    $('#percent').progressbar('value', (Math.floor(done/total*1000)/10));

    				};
    			}
    			xhr.onreadystatechange = function(e) {
    				if ( 4 == this.readyState ) {
    					console.log(this);
    					$('#src').val(this.responseText);
    					$('#dialog').dialog('close');
    					xhr = null;
    				}
    			};
    			xhr.open('post', '/index/fileupload', true);
    			xhr.send(formdata);
    		}, false);
    	}
    
    T 1 Reply Last reply
    0
    • Z ziggyfish

      Hi, In firefox, and chrome, I have a progress bar when someone uploads a file, however the same code doesn't work in IE (surprise surprise), it fails on:

      var file = this.files[0];

      My question is how do I do the equivalent for IE? Pointing me to the documentation would best. code is:

      function uploadImage(){
      $('#percent').progressbar({
      value: 0
      });
      $( "#dialog" ).dialog({
      resizable: false,
      height:150,
      modal: true,
      buttons: {
      Cancel: function() {
      if (xhr){
      xhr.abort();
      xhr = null;
      }
      $( this ).dialog( "close" );
      }
      }
      });
      document.getElementById('photo').addEventListener('change', function(e) {
      var file = this.files[0];
      var formdata = new FormData();
      formdata.append('file', file);
      xhr = new XMLHttpRequest();
      xhr.file = file;
      xhr.addEventListener('progress', function(e) {
      var done = e.position || e.loaded, total = e.totalSize || e.total;
      $('#percent').progressbar('value', (Math.floor(done/total*1000)/10));
      }, false);
      if ( xhr.upload ) {
      xhr.upload.onprogress = function(e) {
      var done = e.position || e.loaded, total = e.totalSize || e.total;
      $('#percent').progressbar('value', (Math.floor(done/total*1000)/10));

      				};
      			}
      			xhr.onreadystatechange = function(e) {
      				if ( 4 == this.readyState ) {
      					console.log(this);
      					$('#src').val(this.responseText);
      					$('#dialog').dialog('close');
      					xhr = null;
      				}
      			};
      			xhr.open('post', '/index/fileupload', true);
      			xhr.send(formdata);
      		}, false);
      	}
      
      T Offline
      T Offline
      twseitex
      wrote on last edited by
      #2

      try to find a file object or collection for IE at http://msdn.microsoft.com/en-us/library/ms533050.aspx

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups