Foros del Web » Programando para Internet » PHP »

La funcion getimagesize no reconoce la imagen

Estas en el tema de La funcion getimagesize no reconoce la imagen en el foro de PHP en Foros del Web. Hola muy buenas, Me esta pasando un cosa que no entiendo, hace tiempo cree una videoteca, y en alta-peliculas, pues habia un formulario con insercion ...
  #1 (permalink)  
Antiguo 23/01/2010, 14:38
 
Fecha de Ingreso: julio-2009
Mensajes: 111
Antigüedad: 14 años, 9 meses
Puntos: 0
La funcion getimagesize no reconoce la imagen

Hola muy buenas,

Me esta pasando un cosa que no entiendo, hace tiempo cree una videoteca, y en alta-peliculas, pues habia un formulario con insercion de imagenes las cuales las trataba en un script que me iba, ahora estoy haciendo un blog y la verdad esq ese script me va de perlas... pero resulta que en el blog no funciona..

Código PHP:
<?php
// tipos Mime que aceptamos
$TipMime = array("image/jpg""image/jpeg""image/pjpeg""image/gif""image/png""image/x-png");


// Obtenemos la información de la imagen
$name $_FILES['caratula']['name'];
$type $_FILES['caratula']['type'];
$size $_FILES['caratula']['size'];
$tmp_name $_FILES['caratula']['tmp_name'];
$error $_FILES['caratula']['error'];

$archivoTemp=getimagesize($_FILES['caratula']['tmp_name']);

// Verificamos si el archivo es una imagen 
if (!in_array($type$TipMime)) {
    
// in_array: revisa si un valor existe en una matriz
    
    
$msgImagen "El archivo $name no es válido";
    
} else {

    
$msgImagen "La imagen $name tiene el formato válido esperado";

    
// Creamos el thumbnail según el tipo de imagen, a partir del fichero temporal
    
switch($type) {
        case 
$TipMime[0]:
            
$imagen imagecreatefromjpeg($tmp_name);
            break;
        case 
$TipMime[1]:
            
$imagen imagecreatefromjpeg($tmp_name);
            break;
        case 
$TipMime[2]:
            
$imagen imagecreatefromjpeg($tmp_name);
            break;
        case 
$TipMime[3]:
            
$imagen imagecreatefromgif($tmp_name);
            break;
        case 
$TipMime[4]:
            
$imagen imagecreatefrompng($tmp_name);
            break;
        case 
$TipMime[5]:
            
$imagen imagecreatefrompng($tmp_name);
            break;
    }


    
// Definimos la medida máxima...
    
$thumb_max 150;  
    
$FotoG_max 600

    
    if (
$archivoTemp[0] > $archivoTemp[1]) { // anchura > altura
    
            
            
$thumb_w $thumb_max// El ancho es el tamaño maximo
            
$thumb_h round(($archivoTemp[1] / $archivoTemp[0])*$thumb_max);
            
//...de la grande
            
$FotoG_w $FotoG_max;
            
$FotoG_h round(($archivoTemp[1] / $archivoTemp[0])*$FotoG_max);
            
    } else { 
// Si es vertical...
            
            
            
$thumb_w round(($archivoTemp[0] / $archivoTemp[1])*$thumb_max);
            
$thumb_h $thumb_max;
            
//...de la grande
            
$FotoG_w round(($archivoTemp[0] / $archivoTemp[1])*$FotoG_max);
            
$FotoG_h $FotoG_max;
    }
    
    
    
$thumb imagecreatetruecolor($thumb_w$thumb_h);
    
$FotoG imagecreatetruecolor($FotoG_w$FotoG_h);
    
    
imagecopyresampled($thumb$imagen0,0,0,0$thumb_w$thumb_himagesx($imagen), imagesy($imagen));
    
    
imagecopyresampled($FotoG$imagen0,0,0,0$FotoG_w$FotoG_himagesx($imagen), imagesy($imagen));
    
    
    
imagedestroy($imagen);

    
//definimos las rutas
    
$carpetaThumbs "../img/"
    
$carpetaFotoG "../img/";

    
//damos salida a la imagen
    
switch($type) {
        case 
$TipMime[0]:
            
imagejpeg($thumb$carpetaThumbs.'T'.$name);
            
imagejpeg($FotoG$carpetaFotoG.$name);
            break;
        case 
$TipMime[1]:
            
imagejpeg($thumb$carpetaThumbs.'T'.$name);
            
imagejpeg($FotoG$carpetaFotoG.$name);
            break;
        case 
$TipMime[2]:
            
imagejpeg($thumb$carpetaThumbs.'T'.$name);
            
imagejpeg($FotoG$carpetaFotoG.$name);
            break;
        case 
$TipMime[3]:
            
imagegif($thumb$carpetaThumbs.'T'.$name);
            
imagegif($FotoG$carpetaFotoG.$name);
            break;
        case 
$TipMime[4]:
            
imagepng($thumb$carpetaThumbs.'T'.$name);
            
imagepng($FotoG$carpetaFotoG.$name);
            break;
        case 
$TipMime[5]:
            
imagepng($thumb$carpetaThumbs.'T'.$name);
            
imagepng($FotoG$carpetaFotoG.$name);
            break;
    }

    
$tumbFinal 'img/'.'T'.$name;
    
$FotoFinal 'img/'.$name;
    
    
imagedestroy($thumb);
    
imagedestroy($FotoG);
    @
unlink($_FILES['caratula']['tmp_name']);
}
?>
En este caso me dice que la funcion getimagesize esta vacia y lo curioso esq en la videoteca me va fenomenal...

Si quereis pongo mas informacion...
Muchas gracias
  #2 (permalink)  
Antiguo 23/01/2010, 14:50
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: La funcion getimagesize no reconoce la imagen

como es el formulario que utilizas para subir el archivo??
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 23/01/2010, 15:01
 
Fecha de Ingreso: julio-2009
Mensajes: 111
Antigüedad: 14 años, 9 meses
Puntos: 0
Respuesta: La funcion getimagesize no reconoce la imagen

Esta es la pagina que recoje todas las variables:


Código PHP:
<?php 
require_once('cnx.php');

if (isset (
$_POST['enviar'])) {

    if (!empty(
$_POST['titulos']) && !empty($_POST['resumen']) && !empty($_POST['noticia']) && !empty($_POST['autor']) && $_POST['seccion']!="nada" && !empty($_FILES['caratula']['tmp_name'])){
        
            
                
$titulo=$_POST['titulos'];
                
$resumen=$_POST['resumen'];
                
$noticia=$_POST['noticia'];
                
$autor=$_POST['autor'];
                
$seccion=$_POST['seccion'];
                
                
//formateamos las imagenes
                
require('formatImg.php');
                
                
$fecha=time();
                require_once(
'cnx.php');
                
$sqlInsert ="INSERT INTO noticias (titulo, resumen, noticia, vista, fecha, autor, Caratula, Thumbnail, id_seccion) VALUES ('$titulo', '$resumen', '$noticia', '0', $fecha, '$autor', '$FotoFinal', '$tumbFinal', $seccion);";
                
mysql_query($sqlInsert$idcon) or die ('Error en la insercion de noticia.');
                echo 
$sqlInsert;
        
        
        
    }else{
    
$msg'Todos los campos son obligatorios';
    }

}
$sqlNoticias="SELECT * FROM `seccion`";
$resultNoticias =mysql_query ($sqlNoticias$idcon) or die ("error Noticia");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Administrador</title>
<link href="../css/pablo.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="../tinymce/jscripts/tiny_mce/tiny_mce.js"> </script>
   <script language="javascript" type="text/javascript">
      tinyMCE.init({
         mode : "textareas",
         theme : "advanced",
         theme_advanced_buttons1 : "bullist,numlist,forecolor,bold, italic, underline, separator, justifyleft, justifycenter, justifyright, justifyfull,cut,copy,paste ",
        theme_advanced_buttons2 : "formatselect, fontselect, fontsizeselect,link,unlink ",
        theme_advanced_buttons3 : "",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        entity_encoding : "raw"

      });
   </script>
</head>
<body>

<div id="madre">
<div id="cpanel">
<h1><img src="../img/cpanel.png" width="30" height="30" alt="cpanel" title="cpanel" />Panel de Control</h1>
</div>

<div id="izq">
<p >Esta columna será para los enlaces que te llevarán a eliminar/modificar/insertar noticias/comentarios, etc...</p>
<br />
<p align="center" class="negrita">Noticias</p>
<ul>
      <li class="alineadoul"><a href="#">Subir noticas</a></li>
      <li class="alineadoul"><a href="#">Modificar noticia</a></li>
      <li class="alineadoul"><a href="#">Eliminar noticas</a></li>
</ul>    
<br />
<p align="center" class="negrita">Imagenes</p>
<ul>
      <li class="alineadoul"><a href="#">Directorio de imagenes</a></li>
      <li class="alineadoul"><a href="#">Eliminar imagen</a></li>
      <li class="alineadoul"><a href="#">Subir imagen</a></li>
</ul> 
<br />
<p align="center" class="negrita">Comentarios</p>
<ul>
      <li class="alineadoul"><a href="#">Eliminar Comentario</a></li>
      <li class="alineadoul"><a href="#">Añadir comentario</a></li>
      </ul> 
<br />
<p align="center" class="negrita">Otros</p>
<ul>
      <li class="alineadoul"><a href="#">Mandar boletin</a></li>
      <li class="alineadoul"><a href="#">Dar de baja a usuarios</a></li>
      <li class="alineadoul"><a href="#">Ingresar usuario</a></li>
      </ul> 
                
</div>

<div id="der">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form1" id="form1">
<table>
<tr>
    <td ><?php echo $msg; echo $msgImagen?></td>
    <td></td>
  </tr>
<tr>
    <th><label for="titulos">Titulo</label></th>
    <td>
      <input name="titulos" type="text" id="titulos" value="<?php echo $_POST['titulos']; ?>" /></td>
  </tr>
  <tr>
    <th><label for="resumen">Resumen</label></th>
    <td>
      <textarea name="resumen" id="resumen" cols="45" rows="3"><?php echo $_POST['resumen']; ?></textarea></td>
  </tr>
  <tr>
    <th> <label for="noticia">Su noticia</label></th>
    <td>
<textarea name="noticia" id="noticia" cols="60" rows="20"><?php echo $_POST['noticia']; ?></textarea>
  </td>
  </tr>
  <tr>
    <th><label for="autor">Autor</label></th>
    <td>
      <input name="autor" type="text" id="autor" value="<?php echo $_POST['autor']; ?>" /></td>
  </tr>
    <th><label for="seccion">Seccion :</label></th>
    <td>
      <select name="seccion" id="seccion">
      <option value="nada"> Seleccione...</option>
       <?php 
      
while($filas=mysql_fetch_assoc($resultNoticias)) {
      echo 
'<option value="'.$filas['id_seccion'].'">'.$filas['seccion'].'</option>';
      }
      
?>
      </select></td>
  </tr>
  <tr>
    <th><label for="imagen">Imagen :</label></th>
    <td>
      
      <input type="hidden" name="max_file_size" id="2000000" /><input type="file" name="caratula" id="caratula" /></td>
  </tr>
  
  <tr>
    <td align="center" bgcolor="#CC3333" colspan="2"><input name="borrar" id="borrar" type="reset" value="Borrar"/>
      <input name="enviar" id="enviar" type="submit" value="Enviar" /></td>
    
    </tr>
</table>
</form>
</div>

</div>
<div id="pie">
</div> 
</body>
</html>
  #4 (permalink)  
Antiguo 23/01/2010, 17:14
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: La funcion getimagesize no reconoce la imagen

pues se nota que te hace falta el enctype de tu formulario...
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #5 (permalink)  
Antiguo 23/01/2010, 17:22
 
Fecha de Ingreso: julio-2009
Mensajes: 111
Antigüedad: 14 años, 9 meses
Puntos: 0
Respuesta: La funcion getimagesize no reconoce la imagen

Código HTML:
Ver original
  1. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form1" id="form1">
  2. <tr>
  3.     <td ><?php echo $msg; echo $msgImagen; ?></td>
  4.     <td></td>
  5.   </tr>
  6. <tr>
  7.     <th><label for="titulos">Titulo</label></th>
  8.     <td>
  9.       <input name="titulos" type="text" id="titulos" value="<?php echo $_POST['titulos']; ?>" /></td>
  10.   </tr>
  11.   <tr>
  12.     <th><label for="resumen">Resumen</label></th>
  13.     <td>
  14.       <textarea name="resumen" id="resumen" cols="45" rows="3"><?php echo $_POST['resumen']; ?></textarea></td>
  15.   </tr>
  16.   <tr>
  17.     <th> <label for="noticia">Su noticia</label></th>
  18.     <td>
  19. <textarea name="noticia" id="noticia" cols="60" rows="20"><?php echo $_POST['noticia']; ?></textarea>
  20.   </td>
  21.   </tr>
  22.   <tr>
  23.     <th><label for="autor">Autor</label></th>
  24.     <td>
  25.       <input name="autor" type="text" id="autor" value="<?php echo $_POST['autor']; ?>" /></td>
  26.   </tr>
  27.     <th><label for="seccion">Seccion :</label></th>
  28.     <td>
  29.       <select name="seccion" id="seccion">
  30.       <option value="nada"> Seleccione...</option>
  31.        <?php
  32.      while($filas=mysql_fetch_assoc($resultNoticias)) {
  33.      echo '<option value="'.$filas['id_seccion'].'">'.$filas['seccion'].'</option>';
  34.       }
  35.       ?>
  36.       </select></td>
  37.   </tr>
  38.   <tr>
  39.     <th><label for="imagen">Imagen :</label></th>
  40.     <td>
  41.      
  42.       <input type="hidden" name="max_file_size" id="2000000" /><input type="file" name="caratula" id="caratula" /></td>
  43.   </tr>
  44.  
  45.   <tr>
  46.     <td align="center" bgcolor="#CC3333" colspan="2"><input name="borrar" id="borrar" type="reset" value="Borrar"/>
  47.       <input name="enviar" id="enviar" type="submit" value="Enviar" /></td>
  48.    
  49.     </tr>
  50. </form>

Bueno el formulario es este... he puesto lo otro para q se viera los campos q recojo..
  #6 (permalink)  
Antiguo 23/01/2010, 17:35
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: La funcion getimagesize no reconoce la imagen

Cita:
Iniciado por pateketrueke Ver Mensaje
pues se nota que te hace falta el enctype de tu formulario...

Código HTML:
<form enctype="multipart/form-data"> 
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #7 (permalink)  
Antiguo 24/01/2010, 07:59
 
Fecha de Ingreso: julio-2009
Mensajes: 111
Antigüedad: 14 años, 9 meses
Puntos: 0
Respuesta: La funcion getimagesize no reconoce la imagen

Vale muchas gracias, que despiste!!!!

Etiquetas: funcion, getimagesize, reconoce
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 12:53.