Ver Mensaje Individual
  #9 (permalink)  
Antiguo 22/10/2009, 20:59
leophp
 
Fecha de Ingreso: julio-2002
Ubicación: stgo rec
Mensajes: 438
Antigüedad: 21 años, 9 meses
Puntos: 3
Respuesta: bajar archivo desde mysql al servidor

Ya aqui esta el codigo terminado y funcionado.

Solo un detalle, al bajar la imagen pone el nombre del scrip (nombre_archivo.php) intente enviar el header con el nombre del archivo pero no funciono.

Código:
<?php 
	
	$idimagen=$_GET["idimagen"];
	//Obtengo foto desde la base de datos
	if(is_numeric($idimagen)){	
		$sql="SELECT file_name, file FROM fotos WHERE imagen='$idimagen';";
		$resultsql = mysql_query($sql, $con_bdd_colegio);
		if(mysql_num_rows($resultsql)==1){ 
			$row_foto = mysql_fetch_array($resultsql);
		}
	}
		
	//Crea el archivo temporal en el servidor
	$nombre_temp = tempnam("tmp", "picm");	
	$gestor = fopen($nombre_temp, "a");
	fwrite($gestor, $row_foto[1]);
	fclose($gestor);
	
	//Ajusta la imagen
	
	//Ancho y alto
	$anchura=180;
	$hmax=180;	
	$nombre=$nombre_temp;
	$datos = getimagesize($nombre);
	if($datos[2]==1){$img = @imagecreatefromgif($nombre);}
	if($datos[2]==2){$img = @imagecreatefromjpeg($nombre);}
	if($datos[2]==3){$img = @imagecreatefrompng($nombre);}
	$ratio = ($datos[0] / $anchura);
	$altura = ($datos[1] / $ratio);
	if($altura>$hmax){$anchura2=$hmax*$anchura/$altura;$altura=$hmax;$anchura=$anchura2;}
	$thumb = imagecreatetruecolor($anchura,$altura);
	imagecopyresampled($thumb, $img, 0, 0, 0, 0, $anchura, $altura, $datos[0], $datos[1]);
	if($datos[2]==1){header("Content-type: image/gif");imagegif($thumb);}
	if($datos[2]==2){header("Content-type: image/jpeg");imagejpeg($thumb);}
	if($datos[2]==3){header("Content-type: image/png");imagepng($thumb);}	
	imagedestroy($thumb);
	
	//Elimina el archivo temporal
	unlink($nombre_temp);	
?>
__________________
Saludos
Leo