Foros del Web » Programando para Internet » PHP »

True y False

Estas en el tema de True y False en el foro de PHP en Foros del Web. Hola, tengo un script donde subo imágenes pero solo quiero subir JPG, GIF y PNG... Este es el script como hago??? Código PHP: <table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> ...
  #1 (permalink)  
Antiguo 03/12/2007, 20:44
 
Fecha de Ingreso: diciembre-2006
Mensajes: 294
Antigüedad: 17 años, 4 meses
Puntos: 2
True y False

Hola, tengo un script donde subo imágenes pero solo quiero subir JPG, GIF y PNG...

Este es el script como hago???

Código PHP:
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="50%">
<div align="center">
<form action="index.php" method="post" enctype="multipart/form-data" name="form1">
<span class="Estilo2">Archivo</span>
<br>
<input name="archivo" type="file" id="archivo" class="file">
<br><br>
<input name="boton" id="boton" class="boton" type="submit" value="Subir Imagen!">
</form>
</div>
</td>
<td width="50%" style="border: 1px solid #0099FF; background-color: #88CFFF">
<b>Solo se admiten archivo con formato JPG, GIF y PNG.</b>
<br>
Tamaño máximo aceptado:<span style="color:#FF0000"> 300KB</span>.
</td>
</tr>
</table>
<br><br>
<?
if($boton) {

$tipo $_FILES['archivo']['type'];
$tamaño $_FILES['archivo']['size'];

if (
is_uploaded_file($HTTP_POST_FILES['archivo']['tmp_name'])) {

if(
$HTTP_POST_FILES['archivo']['size'] < 300000) {

if(
$HTTP_POST_FILES['archivo']['type']=="image/gif" || "image/jpeg" || "image/png") {
$info pathinfo($_FILES['archivo']['name']);
$nnombre substr(md5(uniqid(rand())),0,10).".".$info['extension'];
$destino =  "".$nnombre;
copy($_FILES['archivo']['tmp_name'], $destino);

$subio true;
}
}
}

   if(
$subio) {
      echo 
'<table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td>
<div align="center">
<img src="'
.$nnombre.'">
</div>
</td>
</tr>
<tr>
<td>&nbsp;
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%">
<table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
</tr>
<tr>
<td>
<div align="center">
<b>URL</b>
</div>
</td>
</tr>
<tr>
<td>
<div align="center">
<textarea name="textarea4" cols="50" rows="2" class="file">http://www.host-image.com.ar/'
.$nnombre.'</textarea>
</div>
</td>
</tr>
<tr>
<td>&nbsp;
</td>
</tr>
<tr>
<td>
<div align="center">
<b>C&oacute;digo para foros</b>
</div>
</td>
</tr>
<tr>
<td>
<div align="center">
<textarea name="textarea4" cols="50" rows="2" class="file">[url=http://www.host-image.com.ar][img=http://www.host-image.com.ar/'
.$nnombre.'][/url]</textarea>
</div>
</td>
</tr>
<tr>
<td>&nbsp;
</td>
</tr>
<tr>
<td>
<div align="center">
<b>C&oacute;digo HTML</b>
</div>
</td>
</tr>
<tr>
<td>
<div align="center">
<textarea name="textarea4" cols="50" rows="2" class="file"><a href="http://www.host-image.com.ar"><img src="http://www.host-image.com.ar/'
.$nnombre.'" border="0" /></a></textarea>
</div>
</td>
</tr>
</table>
</td>
<td width="50%" valign="top">
<br><br>
   <b>Nombre:</b>    <a href="'
.$nnombre.'" target="_blank">'.$nnombre.'</a>
<br><br>
   <b>Tipo:</b>    "'
.$tipo.'"
<br><br>
   <b>Tamaño:</b>    <span style="color:#FF0000">"'
.$tamaño.'"</span> bytes
</td>
</tr>
</table>
</td>
</tr>
</table>'
;
   } else {
      echo 
"El archivo no se pudo enviar. Recuerda que debe ser un archivo JPG, GIF o PNG y el tamaño no puede exceder los 300KB";
   }
   die();
}
  #2 (permalink)  
Antiguo 03/12/2007, 22:06
Avatar de emiliodeg  
Fecha de Ingreso: septiembre-2005
Ubicación: Córdoba
Mensajes: 1.830
Antigüedad: 18 años, 7 meses
Puntos: 55
Re: True y False

primero q nada es recomendable utilizar el arreglo $_FILES

if(
$_FILES['archivo']['type']=="image/gif" ||
$_FILES['archivo']['type']=="image/jpeg" || $_FILES['archivo']['type']=="image/png") {
echo "formato valido!";
}
__________________
Degiovanni Emilio
developtus.com
  #3 (permalink)  
Antiguo 03/12/2007, 22:06
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Re: True y False

Cual es tu duda?

Saludos.
  #4 (permalink)  
Antiguo 04/12/2007, 01:56
 
Fecha de Ingreso: octubre-2004
Mensajes: 2.627
Antigüedad: 19 años, 5 meses
Puntos: 48
Re: True y False

$_FILES['archivo']['type'] lo rellena el navegador, y por ejemplo lo que para Firefox es un image/jpeg para nuestro querido IE es un image/pjpeg . Asi que lo mejor para comprobar las imagenes es usar getimagesize() .
  #5 (permalink)  
Antiguo 04/12/2007, 14:39
 
Fecha de Ingreso: diciembre-2006
Mensajes: 294
Antigüedad: 17 años, 4 meses
Puntos: 2
Re: True y False

Gracias. Mi duda era porque lo que usaba normalmente no me daba bola, es decir, cualquiera podia subir cualquier tipo de archivo

Gracias.
  #6 (permalink)  
Antiguo 04/12/2007, 15:22
Avatar de emiliodeg  
Fecha de Ingreso: septiembre-2005
Ubicación: Córdoba
Mensajes: 1.830
Antigüedad: 18 años, 7 meses
Puntos: 55
Re: True y False

en estos casos te conviene comrpobar tamiben la extension de archivo
__________________
Degiovanni Emilio
developtus.com
  #7 (permalink)  
Antiguo 04/12/2007, 18:43
 
Fecha de Ingreso: septiembre-2007
Mensajes: 220
Antigüedad: 16 años, 6 meses
Puntos: 1
Re: True y False

Todos los archivos pueden cambiarse de extensión, mejor el mime.
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 00:00.