|
Posted by naixn on 12/09/06 11:26
eholz1 wrote :
> Hello Group,
>
> Perhaps you can help me. I have a mysql db, that holds images.
> Images are encoded using base64_decode/encode, etc. Image data seems
> fine.
> I have a view.php page that is supposed to show the image, and an
> image.php page that accesses
> the database, retrives the image data, and then (theoretically) prints
> the decoded data to the page.
> below is the view.php page code: problem area the img tag src no
> worky.
>
> What am i missing (having stolen the idea for this from the web!!!!
> thanks,
> eric
> /*******************************************************************/
> <html>
> <head>
> <title>Get The Image</title>
> <link rel="stylesheet" type="text/css" href="css/csssmall.css" />
> </head>
> <body>
> <center><img src="testimage/Sunset.jpg" width="300" border="1"
> alt="Image of Sunset"></center>
> <p class="para-color"><?php echo 'Beautiful Image' ?></p>
> <br>
> <center><img src="image.php?img=3" width="200" border="1" alt="Image of
> Thelma Todd"></center>
> <p class="para-color"><?php echo '\'Nother Beautiful Image' ?></p>
> </body>
> </html>
> /******************************************************************/
>
> below is the image.php code:
> /**********************************************************************
> <?php
> $dbhost = 'localhost';
> $dbuser = 'auser';
> $dbpass = 'apassword';
> $dbcnx = @mysql_connect($dbhost,$dbuser,$dbpass);
>
> if (!$dbcnx)
> {
> echo( "connection to database server failed!");
> exit();
> }
> if (! @mysql_select_db("portfolio") )
> {
> echo( "Image Database Not Available!" );
> exit();
> }
> ?>
> <?php
> $img = $_REQUEST["img"];
> ?>
>
> <?php
> $result = @mysql_query("SELECT * FROM images WHERE id=" . $img . "");
>
> if (!$result)
> {
> echo("Error performing query: " . mysql_error() . "");
> exit();
> }
> while ( $row = @mysql_fetch_array($result) )
> {
> $imgid = $row["id"];
> $encodeddata = $row["sixfourdata"];
> $title = $row['title'];
> }
> ?>
> <?php
> //echo $encodeddata;print??
> echo base64_decode($encodeddata);
> //echo $prefix . $encodeddata;
> ?>
> /*************************************************************************
>
Why do you always open/close the PHP tags? There's no use for it.
The matter in here is that you forgot to tell your browser that the data you're
sending are not plain text or PHP rendering, but a picture.
Do it by writing :
header('Content-Type: image/jpeg');
echo base64_decode($encodeddata);
--
Naixn
http://fma-fr.net
[Back to original message]
|