2008-09-05 11 views

Répondre

86

Cela fonctionne dans IE (et FF, je crois):

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

ce morceau de code fonctionne dans mon environnement local, espérons qu'il fonctionne aussi en direct

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);"/> 

Appelez cette fonction au changement.

Questions connexes