Foros del Web » Programando para Internet » Javascript »

limitar la subida de archivos

Estas en el tema de limitar la subida de archivos en el foro de Javascript en Foros del Web. Hola estoy intentando usar una funcion que esta en este foro y descarto que puede tener errores asi que pienso que soy yo que algo ...
  #1 (permalink)  
Antiguo 08/09/2009, 08:49
 
Fecha de Ingreso: julio-2009
Mensajes: 311
Antigüedad: 14 años, 9 meses
Puntos: 0
Pregunta limitar la subida de archivos

Hola estoy intentando usar una funcion que esta en este foro y descarto que puede tener errores asi que pienso que soy yo que algo esoy haciendo mal
Aca pongo el link es la FAQ140
http://www.forosdelweb.com/f13/faqs-...25/index5.html
Es la funcion que permite limitar que se suban archvios de acuerdo al tipo de extension que tenga el archivo
pegue cuidadosamente el cogido en la parte superir de mi pagina
y puse el onBlur='LimitAttach(this,n);' en el input que corresponde
Sustitui la n por un 1 pues queiro que solo sean imagenes
Sin embargo funciona mal pues
Si intento subir algun tipo de imagen que no es la extension que se espedifican me sale el cartelito que indica que son pueden ser tales extensiones
Hasta ahi bien.
Pero quise ir mas alla e intentar subir un archivo de word sin modfiicar la opcion de extensions y en lugar de salir la leyeda que me deberia decr que no es una extension valida , lo subio o por lo menos guardo en la base de datos el nombre del archivo con su punto doc.
en otras ocaciones no lo sube pero se cuelga la pagina
Si alguien me tira una linea de que puedo estar haciendo mal
Comprenderan que mis conociemtos son muy pocos pero con sacrficio voy dia a dia aprendiendo un poco mas
Gracias si leiste todo esto


#Layer6 {
position:absolute;
width:50px;
height:1px;
z-index:6;
background-color: #FFFFFF;
left: 285px;
}
.Estilo27 {color: #000000; font-size: 24px; font-weight: bold; }
-->
</style>
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v; }
}

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("Sólo se pueden subir archivos con extensiones " + (extArray.join(" ")) + "\n Seleccione un nuevo archivo");
}
}



//-->
</script>
</head>
<body>

<p>&nbsp;</p>
<p><br>
<br>
</table>
</p>
<p>&nbsp;</p>
<div id="Layer1">
<div align="right">
<p><a href="index.php"><img src="images/bannerp.gif" width="391" height="112" border="0" /></a> </p>
<p>&nbsp; </p>
</div>
<table width="200" border="1">
<tr>
<th scope="col"><div align="left"><img src="images/agregar.jpg" width="220" height="40" onclick="MM_showHideLayers('Layer1','','show','Lay er2','','show','Layer3','','hide','Layer4','','hid e','Layer5','','show')" /></div></th>
<th scope="col"><img src="images/editar.jpg" width="220" height="40" onclick="MM_showHideLayers('Layer1','','show','Lay er2','','hide','Layer3','','show','Layer4','','hid e','Layer5','','show')" /></th>
<th scope="col"><img src="images/eliminar.jpg" width="220" height="40" onclick="MM_showHideLayers('Layer1','','show','Lay er2','','hide','Layer3','','hide','Layer4','','sho w','Layer5','','show')" /></th>
</tr>
</table>
<div align="center"></div>
</div>
<div class="Estilo4" id="Layer2">
<p align="right" class="Estilo12">&nbsp;&nbsp; &nbsp;<img src="images/close_32x32.gif" width="20" onclick="MM_showHideLayers('Layer2','','hide')" /> </p>
<form action="procesaProd.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="347" height="253" border="2" align="center" bordercolor="#333333">
<tr>
<caption>
<span class="Estilo27">Nuevo</span>
</caption>
<th width="130" scope="col"><span class="Estilo22">Producto</span></th>
<th width="131" scope="col"><label for="textarea"></label>
<label for="textfield"></label>
<div align="left">
<input name="articulo" type="text" id="textfield" size="28" />
</div></th>
</tr>
<tr>
<th scope="row"><span class="Estilo18"><strong>Descripci&oacute;n</strong></span></th>
<td><label for="textarea"></label>
<textarea name="descripcion" cols="21" rows="4" id="textarea"></textarea></td>
</tr>
<tr>
<th scope="row"><span class="Estilo18"><strong>Precio $ </strong></span></th>
<td><label for="label"></label>
<input name="precio" type="text" id="label" size="27" /></td>
</tr>
<tr>
<th scope="row"><span class="Estilo18"><strong>Imagen</strong></span></th>
<td><label for="file"></label>
//onBlur='LimitAttach(this,n);'llama a función que limita el tipo de archivos que se pueden subir

<input name="archivoAdj" onBlur='LimitAttach(this,1);' type="file" id="file" size="11" /></td>
</tr>
<tr>
<th height="35" scope="row">&nbsp;</th>
<td><label for="Submit"></label>
<input type="submit" name="Submit" value="Enviar" id="Submit" /> &nbsp;&nbsp;&nbsp;&nbsp;
<label for="label2"></label>
<input type="reset" name="Submit2" value="Borrar" id="label2" /></td>
</tr>
</table>
</form>
</p>
<div align="center"></div>
</div>

<div id="Layer3">
<div align="right"><img src="images/close_32x32.gif" width="20" onclick="MM_showHideLayers('Layer3','','hide');MM_ showHideLayers('Layer3','','hide')" /></div>
<div align="right" class="Estilo6">
<div align="center" class="Estilo11">
<form action="editarP.php" method="post" name="form3" class="Estilo19" id="form3">
<p class="Estilo20">Editar </p>
<label for="label5"></label>
<input name="codigo" type="text" id="label5" size="8" />
&nbsp;
<label for="label6"></label>
<input type="submit" name="Submit4" value="Enviar" id="label6" />
</form>
</div>
</div>
</div>

<div id="Layer4">
<div align="right"><img src="images/close_32x32.gif" width="20" onclick="MM_showHideLayers('Layer4','','hide')" /></div>
<div align="right" class="Estilo6">
<div align="center" class="Estilo11">
<table width="215" height="114" border="1" bordercolor="#000000">
<tr>
<th colspan="3" class="Estilo17 Estilo16" scope="col">ELIMINAR</th>
<tr>
<th width="205" class="Estilo18" scope="row"><label for="label4"></label>

<form id="form2" name="form2" method="post" action="deleteP.php">
<span class="Estilo24">C&oacute;digo</span>
<label for="label3"></label>
<input name="codigo" type="text" id="label3" size="8" />&nbsp;
<label for="label4"></label>
<input type="submit" name="Submit3" value="Enviar" id="label4" />
</form>

</table>

<p class="Estilo16">&nbsp;</p>
</div>
</div>
</div>

<div id="Layer5">
<div align="center">
<?
//Conexion con la base
mysql_connect("mysql10.000webhost.com","a3434157_r icardo","webmaster01");

//selecci&oacute;n de la base de datos con la que vamos a trabajar
mysql_select_db("a3434157_login");

//Ejecutamos la sentencia SQL
$result=mysql_query("select * from productos order by idProducto ASC");

?>
</div>
<table width="820" cellspacing="0" cellpadding="5" bgcolor='#000000'bordercolor='#333333' border="4" align="center">
<tr>
<th width="40" scope="col"></th>
<th width="300" scope="col"></th>
<th width="100" scope="col"></th>
<th width="300" scope="col"></th>
<th width="80" scope="col"></th>
</tr>
<tr>
<td height="32"><div align="center" class="Estilo3">C&oacute;digo</div></td>
<td><div align="center" class="Estilo3">
<div align="left">Art&iacute;culo</div>
</div></td>
<td><div align="center" class="Estilo2"></div></td>
<td><div align="center" class="Estilo3">
<div align="left">Descripci&oacute;n</div>
</div></td>
<td><div align="center" class="Estilo3">
<div align="center">Precio ($) </div>
</div></td>
</tr>
</div>
</body>
</html>
  #2 (permalink)  
Antiguo 08/09/2009, 11:08
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Respuesta: limitar la subida de archivos

Tema trasladado desde PHP
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:17.