Ver Mensaje Individual
  #10 (permalink)  
Antiguo 02/05/2011, 13:41
Avatar de Memochipan
Memochipan
 
Fecha de Ingreso: agosto-2009
Mensajes: 14
Antigüedad: 15 años, 5 meses
Puntos: 3
Respuesta: input type='file' name='file' onblur='".LimitAttach(this,1)."

Mira, me di al trabajo de probarlo y funciona bien.

En el archivo donde tienes el input (sea en php o durectamente en html) debes hacer el llamado a la función de Javascript, así:

Código:
<html>
	<head>
		<script type="text/javascript" src="ts.js"></script>
	</head>
	<body>
		<form action="" method="post" id="newtask" name="newtask"> 
			<input type='file' name='file' onblur="LimitAttach(this,1)"/>
		</form>
	</body>
</html>
Y crea un archivo que se llame ts.js y guardalo en la misma carpeta, y en el pega el código de la función:

Código:
function LimitAttach(tField,iType) {
file=tField.value;
if (iType==1) {
extArray = new Array(".gif",".jpg",".png");
}
if (iType==2) {
extArray = new Array(".swf");
}
if (iType==3) {
extArray = new Array(".exe",".sit",".zip",".tar",".swf",".mov",". hqx",".ra",".wmf",".mp3",".qt",".med",".et");
}
if (iType==4) {
extArray = new Array(".mov",".ra",".wmf",".mp3",".qt",".med",".et ",".wav");
}
if (iType==5) {
extArray = new Array(".html",".htm",".shtml");
}
if (iType==6) {
extArray = new Array(".doc",".xls",".ppt");
}
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\") != -1) file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) {
allowSubmit = true;
break;
}
}
if (allowSubmit) {
} else {
tField.value="";
alert("Usted solo puede subir archivos con extensiones " + (extArray.join(" ")) + "\nPor favor seleccione un nuevo archivo");
}
}
Te debería funcionar sin problemas.

P.D. No olvides remover el código javascript de tu archivo .php

Saludos.