<?
include ("connection.php");


$id=$_GET["id"];


$requete="SELECT \"NAME\",\"SPECIES\" from \"EMBRYO\" where \"EMBRYO_ID\"='$id'";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);

$name=$row["NAME"];
$name=str_replace("@","_",$name);
$name=str_replace(" ","_",$row["SPECIES"])."_".$name;


//////////header force download ///////////////////////
header("Content-disposition: attachment; filename=$name.$id.lsm");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: text/plain\n"); // Surtout ne pas enlever le \n
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
header("Expires: 0");


$t="";

$requete="select \"LSM\" from \"EMBRYO\" where \"EMBRYO_ID\"=$id";
$stmt = pg_query($c,$requete);

if($row=pg_fetch_array($stmt))
	{
	$lob = $row["LSM"];
	pg_query ($c, "begin");

	$handle_lo = pg_lo_open($c,$lob,"r");
	$obj=pg_lo_read_all($handle_lo);

	pg_query($c,"end");


	//print $obj;
	$t=$obj;


	}

$filesize=$tmp[count($tmp)-1];


/*
//Trick to avoid the mysterious filesize display at the end of the lob !!
$tmp=explode("\n",$t);
for ($i=0;$i<count($tmp)-1;$i++)
{
print $tmp[$i]."\n";
}


*/







?> 
