Ver Mensaje Individual
  #2 (permalink)  
Antiguo 29/04/2012, 11:58
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Obtener objeto "File" desde un campo de tipo "file" de un formulario en IE

IE y Opera no soportan File, podés usar el valor de value para obtener el path

Ejemplo
Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>titulo</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6.     <script type="text/javascript">
  7.         function infoArchivo() {
  8.             var fileInput = document.getElementById ("subir");
  9.  
  10.             var mensajes = "";
  11.             if ('files' in fileInput) {
  12.                 if (fileInput.files.length == 0) {
  13.                     mensajes = "Seleccione sus archivos<br />Use Ctrl para selecciones múltiples(firefox/chrome/Safari)..";
  14.                 } else {
  15.                     for (var i = 0; i < fileInput.files.length; i++) {
  16.                        mensajes += "<br /><b>" + (i+1) + ". seleccionado</b><br />";
  17.                         var file = fileInput.files[i];
  18.                         if ('name' in file) {
  19.                             mensajes += "nombre: " + file.name + "<br />";
  20.                         }
  21.                         else {
  22.                             mensajes += "nombre: " + file.fileName + "<br />";
  23.                         }
  24.                         if ('size' in file) {
  25.                             mensajes += "tamaño: " + file.size + " bytes <br />";
  26.                         }
  27.                         else {
  28.                             mensajes += "tamaño: " + file.fileSize + " bytes <br />";
  29.                         }
  30.                         if ('mediaType' in file) {
  31.                             mensajes += "tipo: " + file.mediaType + "<br />";
  32.                         }
  33.                     }
  34.                 }
  35.             }
  36.             else {
  37.                 if (fileInput.value == "") {
  38.                     mensajes += "Seleccione uno o más archivos.";
  39.                     mensajes += "<br />Use Ctrl para selecciones múltiples(firefox/chrome/Safari).";
  40.                 }
  41.                 else {
  42.                     mensajes += "El navegador no soporta el objeto File";
  43.                     mensajes += "<br />La ruta al archivo seleccionado es: " + fileInput.value;
  44.                 }
  45.             }
  46.  
  47.             var info = document.getElementById ("info");
  48.             info.innerHTML = mensajes;
  49.         }
  50.     </script>
  51. </head>
  52. <body onload="infoArchivo()">
  53.     <input type="file" id="subir" multiple="multiple" size="60" onchange="infoArchivo()" />
  54.     <div id="info" style="margin-top:30px"></div>
  55. </body>
  56. </html>

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.