2008-09-05 10 views

Antwort

86

Diese in IE funktioniert (und FF, glaube ich):

if(document.getElementById("uploadBox").value != "") { 
    // you have a file 
} 
5

dieses Stück Code in meiner lokalen Umgebung funktioniert, hofft, dass es funktioniert auch in Live-

var nme = document.getElementById("uploadFile"); 
if(nme.value.length < 4) { 
    alert('Must Select any of your photo for upload!'); 
    nme.focus(); 
    return false; 
} 
0
function validateAndUpload(input){ 
    var URL = window.URL || window.webkitURL; 
    var file = input.files[0]; 

    if (file) { 
     var image = new Image(); 

     image.onload = function() { 
      if (this.width) { 
       console.log('Image has width, I think it is real image'); 
       //TODO: upload to backend 
      } 
     }; 

     image.src = URL.createObjectURL(file); 
    } 
};​ 

<input type="file" name="uploadPicture" accept="image/*" onChange="validateAndUpload(this);"/> 

Rufen Sie diese Funktion bei Änderung auf.

Verwandte Themen