Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/01/2004, 08:39
araujo_guntin
 
Fecha de Ingreso: febrero-2003
Mensajes: 165
Antigüedad: 21 años, 2 meses
Puntos: 0
error con func thumbnail

Hola...

tengo un error cuando utilizo la función thumbnail que encontré en el foro.
El error ocurre cuando intento utilizarla varias veces.

código de la funcion thumbnail, solo introduje que calcular el alto porcentual según el ancho.

mil gracias

function thumbnail($file,$dir, $nomb_dest="imglost", $ancho=100,$gif_support=false)
{
if(!file_exists($file)){
return false;
}
if(!is_dir($dir)){
return false;
}
$org_size = GetImageSize ($file);

$alto = round(($org_size[1]*$ancho)/$org_size[0]);

$final = (int) strlen($file) - 4;
$nombre = strtolower(substr($file,0,$final));
$ext = strtolower(substr($file,-4,4));
$nombre = $nombre.$ext;

// $mini = $dir."/".$nombre;
$mini = $dir."/".$nomb_dest;

if($ext==".jpg" || $ext==".jpeg"){
$origen = imageCreateFromJPEG($file);
$imgAncho= imageSx($origen);
$imgAlto = imageSy($origen);
$imagen = imageCreate($ancho,$alto);
ImageCopyResized($imagen,$origen,0,0,0,0,$ancho,$a lto,$imgAncho,$imgAlto);
imageJPEG($imagen,$mini);
}else if($ext==".png"){
$origen = imageCreateFromPNG($file);
$imgAncho= imageSx($origen);
$imgAlto = imageSy($origen);
$imagen = imageCreate($ancho,$alto);
ImageCopyResized($imagen,$origen,0,0,0,0,$ancho,$a lto,$imgAncho,$imgAlto);
imagePNG($imagen,$mini);
}else if(($gif_support==true) && ($ext==".gif")){
$origen = imageCreateFromGIF($file);
$imgAncho= imageSx($origen);
$imgAlto = imageSy($origen);
$imagen = imageCreate($ancho,$alto);
ImageCopyResized($imagen,$origen,0,0,0,0,$ancho,$a lto,$imgAncho,$imgAlto);
imageGIF($imagen,$mini);
}else{
return false;
}
return true;
}


trozo de código donde la utilizo:

/**
* CARGAR FICHERO EN EL SERVIDOR Archivo1
*/
$path=$_SERVER["DOCUMENT_ROOT"]."/images";
$extensiones=array("html","php","exe", "com", "bat", "css", "dll", "so", "h", "gif");
//Archivo1
if (!empty($_FILES['Archivo1']['name'])){
$nombre = fotoname($_FILES['Archivo1']['name'], 1);
$var = explode(".","$nombre");
$num = count($extensiones);
$valor = $num-1;
for($i=0; $i<=$valor; $i++) {
if($extensiones[$i] == $var[1]) {
echo "Tipo de Archivo no admitido";
exit;
}
}

if (is_uploaded_file($HTTP_POST_FILES['Archivo1']['tmp_name']))
{
copy($HTTP_POST_FILES['Archivo1']['tmp_name'], $path."/1".$nombre);
// funcion thumbnail
if(!thumbnail($path."/1".$nombre,"../images", $nombre, 164, false)){
echo "error en creacion de thumbnails";
}
else{
unlink ($path."/1".$nombre);
}
// fin funcion thumbnail
}
else {
echo "Error al subir el archivo, demasiado grande, tamaño maximo 1,4 megas.";
exit;
}
}
//Archivo2
if (!empty($_FILES['Archivo2']['name'])){
$nombre = fotoname($_FILES['Archivo2']['name'], 2);
$var = explode(".","$nombre");
$num = count($extensiones);
$valor = $num-1;
for($i=0; $i<=$valor; $i++) {
if($extensiones[$i] == $var[1]) {
echo "Tipo de Archivo no admitido";
exit;
}
}

if (is_uploaded_file($HTTP_POST_FILES['Archivo2']['tmp_name']))
{
copy($HTTP_POST_FILES['Archivo2']['tmp_name'], "$path/$nombre");
// funcion thumbnail
if(!thumbnail($path."/1".$nombre,"../images", $nombre, 164, false)){
echo "error en creacion de thumbnails";
}
else{
unlink ($path."/1".$nombre);
}
// fin funcion thumbnail

}
else {
echo "Error al subir el archivo, demasiado grande, tamaño maximo 1,4 megas.";
exit;
}
}
//Archivo3
if (!empty($_FILES['Archivo3']['name'])){
$nombre = fotoname($_FILES['Archivo3']['name'], 3);
$var = explode(".","$nombre");
$num = count($extensiones);
$valor = $num-1;
for($i=0; $i<=$valor; $i++) {
if($extensiones[$i] == $var[1]) {
echo "Tipo de Archivo no admitido";
exit;
}
}

if (is_uploaded_file($HTTP_POST_FILES['Archivo3']['tmp_name']))
{
copy($HTTP_POST_FILES['Archivo3']['tmp_name'], "$path/$nombre");
// funcion thumbnail
if(!thumbnail($path."/1".$nombre,"../images", $nombre, 164, false)){
echo "error en creacion de thumbnails";
}
else{
unlink ($path."/1".$nombre);
}
// fin funcion thumbnail

}
else {
echo "Error al subir el archivo, demasiado grande, tamaño maximo 1,4 megas.";
exit;
}
}

/**
* FIN CARGAR FICHERO
*/