Foros del Web » Programando para Internet » PHP »

Ayuda con error php

Estas en el tema de Ayuda con error php en el foro de PHP en Foros del Web. Ayuda!!! Me sale el siguiente error: Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /home/a5122064/public_html/bme_image_uploader.class.php on line 39 Ese archivo es el siguiente: Código: <?php ...
  #1 (permalink)  
Antiguo 22/04/2010, 15:28
 
Fecha de Ingreso: enero-2010
Mensajes: 42
Antigüedad: 14 años, 3 meses
Puntos: 1
Ayuda con error php

Ayuda!!! Me sale el siguiente error:
Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /home/a5122064/public_html/bme_image_uploader.class.php on line 39

Ese archivo es el siguiente:
Código:
<?php
session_start();

class bme_ImageUploader
{

function bme_ImageUploader($maxwidth, $maxheight, $max_filesize, $fieldname)
{

//config all values needed for image uploads
$this->maxwidth = $maxwidth;
$this->maxheight = $maxheight;
$this->max_filesize = $max_filesize;
$this->field = $_FILES[$fieldname]['name'];
$this->field_type = $_FILES[$fieldname]['type'];
$this->field_temp = $_FILES[$fieldname]['tmp_name'];
$this->field_size = $_FILES[$fieldname]['size'];
$this->max_filesize_kb = ($this->max_filesize / 2048);
$this->types_array = array('image/gif','image/pjpeg','image/jpeg','image/jpg','image/x-png','image/png');

}

function uploadfolder()
{
return $this->upload_folder;
}

function upload_image_typecheck()
{
if(!in_array($this->field_type, $this->types_array))
{
$this->is_pic_error = "El tipo de archivo no está permitido.<br />Asegúrate de que la imagen sea <b>jpg, gif o png</b><br /><br /> <a href='subirfoto.php'>Volver</a> <br />" ;
$this->pic_error = TRUE;
}
}

function upload_image_size()
{
$this->imagesize = getimagesize($this->field_temp);
return $this->imagesize;
}

function upload_image_sizecheck()
{
if($this->field_size > $this->max_filesize)
{
$this->is_pic_error = "Su imagen pesa ".$this->field_size." kb<br /> La imagen puede ser de hasta ".$this->max_filesize_kb."kb<br /><br /> <a href='subirfoto.php'>Volver</a> <br />";
$this->pic_error = TRUE;
}
}

function upload_image_width()
{
$this->imagewidth = $this->imagesize[0];
return $this->imagewidth;
}

function upload_image_height()
{
$this->imageheight = $this->imagesize[1];
return $this->imageheight;
}

function upload_image_wh_check()
{
if($this->imagewidth > $this->maxwidth || $this->imageheight > $this->maxheight)
{
$this->is_pic_error = "La imagen no puede superar ".$this->maxwidth."px por ".$this->maxheight."px de tamaño.<br /><br /> <a href='subirfoto.php'>Volver</a> <br />";
$this->pic_error = TRUE;
}
}

function upload_image($extension='', $folder='', $upload_name)
{
//Run error checks
$this->upload_image_typecheck();
$this->uploadfolder();
$this->upload_image_size();
$this->upload_image_width();
$this->upload_image_height();
$this->upload_image_sizecheck();
$this->upload_image_wh_check();
$this->upload_session_name = $upload_name;

//If no errors are thrown and all is well, lets upload the image shall we?
if($this->pic_error == FALSE)
{
//what extenstion are we adding before the image name?
if($extension == FALSE){$this->uniq = date( "m-d-Y-G-i-s" )."_";}else{$this->uniq = $extension;}
//what folder are we uploading image to?
if($folder == FALSE){$this->upload_folder = "imgs";}else{$this->upload_folder = $folder;}

$this->ext = strtolower($this->field);
$this->ext = preg_replace('/\s\s+/', '', $this->ext);
$this->ext = preg_replace('/\'/', '', $this->ext);
$this->ext = str_replace ( ' ', '-', $this->ext );
move_uploaded_file($this->field_temp, $this->upload_folder."/".$this->uniq.$this->ext ) or die ("Couldn't upload ".$this->field."<br />");

//sweet! now the image is uploaded lets go ahead and tell ourselves the name of the new image
$this->upload_image_url();

//UH-OH! Something went wrong. The user was probably stupid, so we shall now tell them what they did wrong
}else{
echo "<div class=\"error\">".$this->is_pic_error."</div>";
}
}

function upload_image_url()
{
$this->newimgurl = "{$this->uniq}{$this->ext}";

$_SESSION['img_upload_success'] = TRUE;
$_SESSION['img_upload_folder'] = $this->upload_folder;
$_SESSION['img_upload_name'] = $this->newimgurl;
$_SESSION[$this->upload_session_name] = $this->newimgurl;

}

function uploaded_image()
{

return $this->newimgurl;

}
function upload_image_reset()
{
$_SESSION['img_upload_success'] = FALSE;
$_SESSION['img_upload_folder'] = FALSE;
$_SESSION['img_upload_name'] = FALSE;
$_SESSION[$this->upload_session_name] = FALSE;

}

function resizeImage($twidth="80", $theight="80", $text="thumb_")
{

if($this->pic_error == FALSE)
{
$n_width = (int)$twidth;
$n_height =(int)$theight;
$tsrc = $this->upload_folder."/ss/".$text.$this->uniq.$this->ext;


if($this->field_type=="image/pjpeg" || $this->field_type=="image/jpeg" || $this->field_type=="image/jpg")
{
$im=ImageCreateFromJPEG($this->upload_folder."/".$this->uniq.$this->ext);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
imagejpeg($newimage,$tsrc);
}elseif($this->field_type=="image/gif")
{
$im=ImageCreateFromGIF($this->upload_folder."/".$this->uniq.$this->ext);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imagecopyresampled($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
//imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
imagegif($newimage,$tsrc);
}elseif($this->field_type=="image/x-png" || $this->field_type=="image/png")
{
$im=ImageCreateFromPNG($this->upload_folder."/".$this->uniq.$this->ext);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
imagepng($newimage,$tsrc);
}
}
}
}
?>
Alguien tiene idea que puede ser? El error sale cuando en el formulario para cargar imagen, apreto el boton "subir imagen" pero sin escribir nada y sin seleccionar ningun archivo.
  #2 (permalink)  
Antiguo 22/04/2010, 15:31
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Ayuda con error php

El error si lo traduces te indica todo, el nombre del archivo no puede estar en blanco, tienes que asegurarte que subas un archivo.

Saludos.
  #3 (permalink)  
Antiguo 22/04/2010, 15:35
Avatar de Carxl
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: Bogotá
Mensajes: 2.993
Antigüedad: 17 años, 8 meses
Puntos: 70
Respuesta: Ayuda con error php

Pues debes hacer ese proceso pero validando que haya un archivo existente. Si no lo haces te seguirá arrojando ese error. Algo así:

Código PHP:
Ver original
  1. if ( $_FILES['nombre_input_tipo_file']['name']){
  2. //si existe un nombre en el input haga todo lo que deba hacer
  3. } else{
  4. //si no arroje un error personalizado :p
  5. }

Pero si quieres validar que subió el archivo y que lo puedes usar usa:

http://www.php.net/manual/en/functio...oaded-file.php

Saludos
__________________
Hay 10 tipos de personas, los que entienden binario y los que no. (Anónimo)
www.programandoweb.com
  #4 (permalink)  
Antiguo 22/04/2010, 15:56
 
Fecha de Ingreso: abril-2010
Mensajes: 83
Antigüedad: 14 años
Puntos: 1
Respuesta: Ayuda con error php

si no me equivoco usas 000webhost de hosting :O :O
  #5 (permalink)  
Antiguo 23/04/2010, 09:38
 
Fecha de Ingreso: enero-2010
Mensajes: 42
Antigüedad: 14 años, 3 meses
Puntos: 1
Respuesta: Ayuda con error php

Mil gracias gente, lo arregle poniendo lo siguiente en la funcion donde me daba error:
Código:
if($_FILES[$fieldname]['name'] !=''){
Si! Uso 000webhost....
como sabes?
saludos!!1

Etiquetas: Ninguno
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 02:28.