Ver Mensaje Individual
  #20 (permalink)  
Antiguo 24/09/2010, 09:22
sandinosaso
 
Fecha de Ingreso: julio-2008
Mensajes: 208
Antigüedad: 15 años, 9 meses
Puntos: 5
Respuesta: Galeria fotos Jquery

NO!!!!...basename es una funcion de php que devuelve el nombre de un archivo sin la base (ejemplo basename("carpeta/fotos/index.php") devuelve index.php...
No se suponia que lo cambiaras por el nombre de tu base...

Ahora bien...

Asi te debe quedar el archivo que mencionas:


Código:
<?php
function resize($img, $thumb_width, $newfilename)
{
$max_width=$thumb_width;

//Check if GD extension is loaded
if (!extension_loaded('gd') && !extension_loaded('gd2'))
{
trigger_error("GD is not loaded", E_USER_WARNING);
return false;
}

//Get Image size info
list($width_orig, $height_orig, $image_type) = getimagesize($img);

switch ($image_type)
{
case 1: $im = imagecreatefromgif($img); break;
case 2: $im = imagecreatefromjpeg($img); break;
case 3: $im = imagecreatefrompng($img); break;
default: trigger_error('Unsupported filetype!', E_USER_WARNING); break;
}

/*** calculate the aspect ratio ***/
$aspect_ratio = (float) $height_orig / $width_orig;

/*** calulate the thumbnail width based on the height ***/
$thumb_height = round($thumb_width * $aspect_ratio);


while($thumb_height>$max_width)
{
$thumb_width-=10;
$thumb_height = round($thumb_width * $aspect_ratio);
}

$newImg = imagecreatetruecolor($thumb_width, $thumb_height);

/* Check if this image is PNG or GIF, then set if Transparent*/
if(($image_type == 1) OR ($image_type==3))
{
imagealphablending($newImg, false);
imagesavealpha($newImg,true);
$transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
imagefilledrectangle($newImg, 0, 0, $thumb_width, $thumb_height, $transparent);
}
imagecopyresampled($newImg, $im, 0, 0, 0, 0, $thumb_width, $thumb_height, $width_orig, $height_orig);

//Generate the file, and rename it to $newfilename
switch ($image_type)
{
case 1: imagegif($newImg,$newfilename); break;
case 2: imagejpeg($newImg,$newfilename); break;
case 3: imagepng($newImg,$newfilename); break;
default: trigger_error('Failed resize image!', E_USER_WARNING); break;
}

return $newfilename;
}


if(basename($_FILES['Foto']['name'])) 
        { 

            $aleatorio = mt_rand(1,1000); 

            $directorio = "images/";
            $directorio_thumb = "images/thumbs/";

            $directorio = $directorio. $aleatorio . basename( $_FILES['Foto']['name']);  
            $directorio_thumb = $directorio_thumb. $aleatorio . basename( $_FILES['Foto']['name']);  

            //Muevo la imagen al directorio $directorio
            move_uploaded_file($_FILES['Foto]['tmp_name], $directorio);
            
           //Creo el thumb de la imagen y la copio a $directorio_thumb con alto      //maximo 120 pixeles
            resize($directorio, 120, $directorio_thumb) ;


    }  

$host              = 'localhost';
$usuario          = 'root';
$password      = '';
$basededatos ='vecinoma_admin';

   $conexion = @mysql_connect($host,$usuario,$password) or die ("Error al   conectarse al host $host con el usuario $usuario");

mysql_select_db($basededatos,$conexion) or die ("Error al seleccionar la base 
$basededatos.");

   $sql = "INSERT INTO Lotes (IDTitulo, Descripcion, url_foto) VALUES ('".$_POST['Titulo']."','".$_POST['Descripcion']."','$directorio')";
   mysql_query($sql,$conexion) or die('Error al guardar por: ' . mysql_error());



?>


PERO DEBES AGREGAR EL CAMPO url_foto en tu tabla Lotes (de paso...porque usas esta y no te creas una tabla con los 3 campos que recomendo jose para identificar asi las imagenes, llamale Imagenes por ejemplo)....si no no te va a andar el codigo de jose...
Ademas ahi faltaba la conexion a la base (con un usuario y un password que uses habitualmente para conectarte) y al servidor....que no se en que servidor lo tienes...ahi te puse localhost que es el local...esos datos tu los tienes que saber.

Aparte asegurate que los campos de la tabla Lotes se llamen IDTitulo, Descripcion y url_foto....EXACTAMENTE ASI!!!!!! respetando mayusculas y minusculas...guion bajo..etc...