Ver Mensaje Individual
  #7 (permalink)  
Antiguo 22/03/2005, 15:43
Avatar de mauricio2004
mauricio2004
 
Fecha de Ingreso: marzo-2004
Mensajes: 264
Antigüedad: 20 años, 1 mes
Puntos: 0
sepo yo tengo una validacion mas perfecta de los archivos gif o jpg

$my_max_file_size = "102400"; # in bytes
$image_max_width = "800";
$image_max_height = "600";
$allowed_types = array("image/bmp","image/gif","image/pjpeg","image/jpeg");
$registered_types = array(
"application/x-gzip-compressed" => ".tar.gz, .tgz",
"application/x-zip-compressed" => ".zip",
"application/x-tar" => ".tar",
"text/plain" => ".html, .php, .txt, .inc (etc)",
"image/bmp" => ".bmp, .ico",
"image/gif" => ".gif",
"image/pjpeg" => ".jpg, .jpeg",
"image/jpeg" => ".jpg, .jpeg",
"application/x-shockwave-flash" => ".swf",
"application/msword" => ".doc",
"application/vnd.ms-excel" => ".xls",
"application/octet-stream" => ".exe, .fla (etc)",
"application/pdf" => ".pdf"
);


function validate_upload($foto) {

global $my_max_file_size, $image_max_width, $image_max_height,$allowed_types,$foto_type,$regis tered_types;

$start_error = "\n<b>Error: </b>\n";

if ($foto == "none") { # Vemos si hay archvios

$error .= "\n<li>La fotografía del producto NO fue modificada</li>";

} else { # Ver si los tipos son los correctos

if (!in_array($foto_type,$allowed_types)) {
$error .= "\nEl tipo de archivo que intenta subir no está permitido por motivos de seguridad, usted sólo puede subir archivos del siguiente tipo.:\n<ul>";
while ($type = current($allowed_types)) {
$error .= "\n<li>" . $registered_types[$type] . " (" . $type . ")</li>";
next($allowed_types);
}
$error .= "\n</ul>";
}

if (ereg("image",$foto_type) && (in_array($foto_type,$allowed_types))) {

$size = GetImageSize($foto);
list($foo,$width,$bar,$height) = explode("\"",$size[3]);

if ($width > $image_max_width) {
$error .= "\n<li>Su imágen no puede ser mas ancha que " . $image_max_width . " pixeles.</li>";
}

if ($height > $image_max_height) {
$error .= "\n<li>Su imágen no puede ser mas alta que " . $image_max_height . " pixeles</li>";
}

}

if ($error) {
$error = $start_error . $error . "\n</ul>";
return $error;
} else {
return false;
}
}
} # END validate_upload


y de aca viene el formulario

if (sizeof($imagen) > 0 && $imagen!="none")
{
$foto_type=$imagen_type;

// Vemos si existe error al subir la imagen

$error = validate_upload($imagen);

if ($foto_type=="image/gif")
$extension=".gif";
elseif ($foto_type=="image/pjpeg")
$extension=".jpg";

$imagen_name=$id_imagen."d".$extension;

if (!$error)
{

if (!@copy($imagen, "../$conf[7]/$imagen_name"))
$imagen_error = "<p><b>ERROR:</b> No se ha podido copiar la imagen <b>$imagen_name</b> en el directorio de imagenes, revise los permisos de escritura de este directorio (/$conf[7]/)</p>";
}
}