Hello, Thanks for your help.  This is what I have for file1.php and
ddownloadfile.php.  What I want is to click on "Donwnload now" link and be
able to get the file out of the database and display it on the browser.
Thank you in adavance, -Teresa

file1.php
-----------
<?php

   while ($row = mysql_fetch_array($result))
   {
?>     
      SOME_HTLM_CODE_TO_DISPLAY_DB_FIELDS_GOES_HERE; 

//      <img src=\"ddownloadfile.php?fileId=<?php echo $row["PicNum"]; ?>\"
>
      <a href="ddownloadfile.php?fileId=<?php echo $row["PicNum"]; ?>" >
         Download Now
      </a></font>
      </td>
      </tr>

<?php                                


ddownloadfile.php
------------------
<?      
$dbQuery = "Select PicNum, size, type, description, Image";
$dbQuery .= " FROM Images WHERE PicNum = $fileId";

$result = mysql_query($dbQuery)
or die ("Could not get file list: " . mysql_error() );
echo "Sent Query successfully<br>";

if ( mysql_num_rows($result) == 1)
{
$fileType = @mysql_result($result,0, "type");
$fileContent = @mysql_result($result, 0, "Image");
$filedesc = @mysql_result($result,0, "description");
$filenum = @mysql_result($result,0, "PicNum");
Header("Content-type: image/gif");
echo $fileContent;
}
else
{
echo "Record does not exist";
} // else

?>                 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 27, 2002 4:56 AM
To: [EMAIL PROTECTED]
Subject: RE: [PHP] Unable to display images on browser


Well, you probably need to do something like this:

----file1.php (where you want to display an image)

<img src="getimage.php?fileId=42">

----end file1


----getimage.php (the <? needs to be on the first line in the file)
<?
 ------------ Code to connect and selected DB not included
 ---------------------
 $dbQuery = "Select PicNum, size, type, description, Image";
 $dbQuery .= " FROM Images WHERE PicNum = $fileId";
 
 $result = mysql_query($dbQuery)
 or die ("Could not get file list: " . mysql_error() );

 if ( mysql_num_rows($result) == 1)
 {
 $fileType = @mysql_result($result,0, "type");
 $fileContent = @mysql_result($result, 0, "Image");
 $filedesc = @mysql_result($result,0, "description");
 $filenum = @mysql_result($result,0, "PicNum");
 //      Header("Content-type: $fileType");         

header ("Content-type: image/gif");
$im = ImageCreateFromString ($fileContent);
ImageGif ($im);

 }                           
 else
 {
   //Insert code to display error.gif
 } // else
?>             
-------end getimage.php

Good Luck
/Joakim


> -----Original Message-----
> From: Narvaez, Teresa [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, February 27, 2002 2:08 AM
> To: 'Dean Householder'; [EMAIL PROTECTED]
> Subject: [PHP] Unable to display images on browser
> 
> 
> Hello, 
>       I do not understand why I can't display images 
> retrieved from MySQL
> on my browser(IE 4.0).  When I retrieve the image from MYSQL I set the
> Header function to change the type of content(image/gif) I am 
> sending to the
> browser. However, the browser displays an box with an X in 
> it.  I would
> greatly appretiate any ideas/help.  Here is the piece of 
> code:  Thanks in
> advance! -Teresa
> 
> <?
> ------------ Code to connect and selected DB not included
> ---------------------
> $dbQuery = "Select PicNum, size, type, description, Image";
> $dbQuery .= " FROM Images WHERE PicNum = $fileId";
> 
> $result = mysql_query($dbQuery)
> or die ("Could not get file list: " . mysql_error() );
> echo "Sent Query successfully<br>";
> 
> if ( mysql_num_rows($result) == 1)
> {
> $fileType = @mysql_result($result,0, "type");
> $fileContent = @mysql_result($result, 0, "Image");
> $filedesc = @mysql_result($result,0, "description");
> $filenum = @mysql_result($result,0, "PicNum");
> //      Header("Content-type: $fileType");         
> Header("Content-type: image/gif");
> echo $fileContent;
> }                           
> else
> {
> echo "Record does not exist";
> } // else
> ?>             
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to