Foros del Web » Programando para Internet » PHP »

problema para mostrar imagenes con funciones

Estas en el tema de problema para mostrar imagenes con funciones en el foro de PHP en Foros del Web. Un amigo diseñador hizo unos retoques para un cliente y ahora no visualiza las fotos. Yo "programo" en php, me contactó para que le dé ...
  #1 (permalink)  
Antiguo 22/10/2008, 14:08
Avatar de arielcasanova  
Fecha de Ingreso: octubre-2004
Ubicación: Bahía Blanca - Argentina
Mensajes: 332
Antigüedad: 19 años, 6 meses
Puntos: 1
problema para mostrar imagenes con funciones

Un amigo diseñador hizo unos retoques para un cliente y ahora no visualiza las fotos. Yo "programo" en php, me contactó para que le dé una mano, pero el programador original a quien no pudo contactar, utiliza un montón de funciones que yo no conozco. Las imágenes están guardadas en la misma base de datos, en campos tipo blob.

Acá va el código (es un archivo muy largo, pongo lo que creo que corresponde) que debería mostrar las fotos:

Código:
<?php
	include("./admin/adf/bdADF.php");
	include("./admin/functions/categoryFunc/gralFunctions.php");
	include("./admin/functions/artistFunc/gralFunctions.php");
	include("./admin/functions/objectFunc/gralFunctions.php");
	connect_db();
	if(isset($_GET["artistId"]) && isset($_GET["categoryId"])){
		$objects = findCategoryObjects($_GET["categoryId"]);
		if(isset($_GET["objectId"]))
			$mainObject = findObjectByPk($_GET["objectId"]);
		$category = findCategoryByPk($_GET["categoryId"]);
		$categories = findCategoryByArtistId($_GET["artistId"]);
		$artist = findartistByPk($_GET["artistId"]);
		//print_r($categories);
	}else{
		echo "Contact your administrator [ERROR: No artistId or categoryId]";
	}
  ?>

<?php
          		if(isset($_GET["objectId"]))
          			$objectIdtoShow = $_GET["objectId"];
          		else
          			$objectIdtoShow = $objects[0]["id"];
?>
                  <img src="./admin/imageDisplayer/showObjImage.php?objectId=<?php echo $objectIdtoShow; ?>"width="389" height="293" border="0" /></td>
Aquí van los archivos gralFunctions.php y showObjImage.php, que debería mostrar la foto

gralFunctions.php

Código:
	function addObject($categoryId, $objectTitleFR, $objDescriptionFR, 

                      $objectTitleEN, $objDescriptionEN, $objectPrice) {

		$query = "select max(object.`displayOrder`) as maxOrder from `object`;";

	$result = mysql_query($query);
		$array = array();
		while( $row = mysql_fetch_assoc($result) ) {
			$array[] = $row;
	}
		$tmp = $array[0]["maxOrder"];
		if( $tmp == null ) $tmp = 0;
		$tmp++;

  	$fpOn = @fopen($_FILES["objectImage"]["tmp_name"][0], "rb");
	  $tfotoOn = @fread($fpOn, filesize($_FILES["objectImage"]["tmp_name"][0]));

	  $tfotoOn = @addslashes($tfotoOn);
	  fclose($fpOn);

	  

	  $fpOff = @fopen($_FILES["objectImage"]["tmp_name"][1], "rb");

	  $tfotoOff = @fread($fpOff, filesize($_FILES["objectImage"]["tmp_name"][1]));

	  $tfotoOff = @addslashes($tfotoOff);

	  fclose($fpOff);



		

		//$query = "INSERT INTO `object` (`title`, `description`, `price`, `mainImage`, `thumbnail`, `displayOrder`, `categoryId`) VALUES ('$objectTitle', '$objDescription', '$objectPrice', '$tfotoOn', '$tfotoOff', $tmp, $categoryId);";

		// LecToro para dos idiomas:

		$query = "INSERT INTO `object` (`title_fr`, `description_fr`,

                            `title_en`, `description_en`, 

                            `price`, `mainImage`, `thumbnail`, 

                            `displayOrder`, `categoryId`) 

                            VALUES ('$objectTitleFR', '$objDescriptionFR', 

                            '$objectTitleEN', '$objDescriptionEN',

                            '$objectPrice', '$tfotoOn', '$tfotoOff', 

                            $tmp, $categoryId);";

		$result = mysql_query($query) or die("<br>".mysql_error());	

	}

	

	function findAllObjects(){

		$query = "select * from object order by object.`displayOrder`;";

		$result = mysql_query($query);

		$array = array();

		while($row = mysql_fetch_assoc($result)){

			$array[] = $row;

		}

		return $array;	

	}

	

	function findObjectsByCatId($categoryId){

		$query = "select * from object where object.categoryId = $categoryId order by object.`displayOrder`;;";

		$result = @mysql_query($query);

		$array = array();

		if(@mysql_num_rows($result) > 0) {

			while($row = @mysql_fetch_assoc($result)){

				$array[] = @$row;

			}

		}

		return $array;	

	}

	

	function findObjectByPK($pk){

		$query = "select * from object where id = $pk;";

		$result = mysql_query($query);

		$array = array();

		while($row = mysql_fetch_assoc($result)){

			$array[] = $row;

		}

		return $array;

	}

	

	/*

	function modifyObject($pk, $objectTitle, $objDescription, $objectPrice){

		$query = "UPDATE `object` SET `title`= '$objectTitle', `description`= '$objDescription', `price`= '$objectPrice' WHERE `id`=$pk;";

		$result = mysql_query($query);

	}

	*/

function modifyObject($pk, $objectTitleFR, $objDescriptionFR, 

                        $objectTitleEN, $objDescriptionEN, $objectPrice) {

		$query = "UPDATE `object` SET 

                  `title_fr`= '$objectTitleFR', `description_fr`= '$objDescriptionFR',

                  `title_en`= '$objectTitleEN', `description_en`= '$objDescriptionEN', 

                  `price`= '$objectPrice' WHERE `id`=$pk;";

		$result = mysql_query($query);

	}

	

	function deleteObject($pk){

		$query = "DELETE FROM `object` WHERE `id`=$pk";

		$result = mysql_query($query);

	}

	

	function moveObjectUp($pk, $catId){

		$brotherObjectsQuery = "select object.`id`, object.`displayOrder` from object where categoryId = $catId order by object.`displayOrder`;";

		$resultBrothers = mysql_query($brotherObjectsQuery);

		//$query = "select object.`id`, object.`displayOrder` from object order by object.`displayOrder`;";

		//$result = mysql_query($query);

		$array = array();

		$i = 0;

		$tmp = 0;

		while($row = mysql_fetch_assoc($resultBrothers)){

			$array[] = $row;

			if($array[$i]["id"] == $pk){

				

				$tmp = $i;

			}

			$i++;

		}

		//print_r($array);

		

		if($tmp != 0){

			$toMoveUp = $array[$tmp]["id"];

			$toUpPosition = $array[$tmp]["displayOrder"];

			$tmp = $tmp - 1;

			$toMoveDown = $array[$tmp]["id"];

			$toDownPosition = $array[$tmp]["displayOrder"];

			

			$query = "UPDATE `object` SET `displayOrder`= $toDownPosition WHERE `id`=$toMoveUp;";

			$result = mysql_query($query) or die("<br>".mysql_error());

			

			$query = "UPDATE `object` SET `displayOrder`= $toUpPosition WHERE `id`=$toMoveDown;";

			$result = mysql_query($query) or die("<br>".mysql_error());

		}

		

		return $array;

	}

	

	function moveObjectDown($pk, $catId){

		$query = "select object.`id`, object.`displayOrder` from object where categoryId = $catId order by object.`displayOrder`;";

		$result = mysql_query($query);

		$array = array();

		$i = 0;

		$tmp = 0;

		while($row = mysql_fetch_assoc($result)){

			$array[] = $row;

			//print_r($array);

			if($array[$i]["id"] == $pk){

				$tmp = $i;

			}

			$i++;

		}

		

		if($tmp < (sizeof($array) - 1)){

			$toMoveUp = $array[$tmp]["id"];

			$toUpPosition = $array[$tmp]["displayOrder"];

			$tmp = $tmp + 1;

			$toMoveDown = $array[$tmp]["id"];

			$toDownPosition = $array[$tmp]["displayOrder"];

			

			$query = "UPDATE `object` SET `displayOrder`= $toDownPosition WHERE `id`=$toMoveUp;";

			$result = mysql_query($query) or die("<br>".mysql_error());

			

			$query = "UPDATE `object` SET `displayOrder`= $toUpPosition WHERE `id`=$toMoveDown;";

			$result = mysql_query($query) or die("<br>".mysql_error());

		}

		

		return $array;

	}

?>
showObjImage.php

Código:
<?php
	header('Content-Type: image/gif;');
	header('Content-Type: image/jpeg;');	
	include("../adf/bdADF.php");
	include("../functions/objectFunc/gralFunctions.php");
	connect_db();

	
	$object = findObjectByPk($_GET["objectId"]);
	$image = $object[0]["mainImage"];
	echo $image;

	
/*
	$query = "select mainImage as image from object where object.id = $objectId;";
	$result = mysql_query($query);
	//echo $result[0]["image"];
	$array = array();
	while($row = mysql_fetch_assoc($result)){
		$array[] = $row;
	}
	echo $array[0]["image"];	
*/
?>


Si alguien puede echarnos una mano, mi amigo está de los pelos, y a mí me está volviendo loco.
como sé algo de php, pensé que sería facil, y he pasado varios períodos de 30 minutos de concentración en el sistema sin poder descularlo.

Gracias!
__________________
Ariel Casanova
diseño y desarrollo web estratégico
www.emporia.com.ar
  #2 (permalink)  
Antiguo 22/10/2008, 14:08
Avatar de arielcasanova  
Fecha de Ingreso: octubre-2004
Ubicación: Bahía Blanca - Argentina
Mensajes: 332
Antigüedad: 19 años, 6 meses
Puntos: 1
Respuesta: problema para mostrar imagenes con funciones

por lo pronto, este archivo sí muestra una imagen:

Código:
<?php
	header('Content-Type: image/gif;');
	header('Content-Type: image/jpeg;');	
	include("../../adf/bdADF.php");
	connect_db();
	if(isset($_GET["categoryId"]))
		$pk = $_GET["categoryId"];
	else if(isset($_GET["objectId"]))
		$pk = $_GET["objectId"];
	else if(isset($_GET["workId"]))
		$pk = $_GET["objectId"];
	else if(isset($_GET["newId"]))
		$pk = $_GET["newId"];
	else if(isset($_GET["artistImage"]))
		$pk = $_GET["artistImage"];
	
	$type = $_GET["picType"];
	
	if($type == "on"){
		$query = "select onImage as image from category where category.id = $pk;";
	} else if($type == "off"){
		$query = "select offImage as image from category where category.id = $pk;";
	} else if($type == "th"){
		$query = "select thumbnail as image from category where category.id = $pk;";
	} else if($type == "main"){
		$query = "select mainImage as image from object where object.id = $pk;";
	} else if($type == "th2"){
		$query = "select thumbnail as image from object where object.id = $pk;";
	} else if($type == "wMain"){
		$query = "select mainImage as image from work where work.id = $pk;";
	} else if($type == "wThumb"){
		$query = "select thumbnail as image from work where work.id = $pk;";
	} else if($type == "newsMain"){
		$query = "select mainImage as image from news where news.id = $pk;";
	} else if($type == "artistImage"){
		$query = "select artistImage as image from artist where artist.id = $pk;";
	}

	$result = mysql_query($query);
	//echo $result[0]["image"];
	$array = array();
	while($row = mysql_fetch_assoc($result)){
		$array[] = $row;
	}
	echo $array[0]["image"];
?>

pero no logro encontrar la relación con el que no la muestra y sí debería...
__________________
Ariel Casanova
diseño y desarrollo web estratégico
www.emporia.com.ar
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 17:18.