You are here: Re: trying to display image from mysql database « PHP Programming Language « IT news, forums, messages
Re: trying to display image from mysql database

Posted by Jerry Stuckle on 12/10/06 02:49

Michael Austin wrote:
> 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;
>> ?>
>> /*************************************************************************
>>
>>
>
> I have never like storing images in databases - I generally have a
> special directory where I have images that are named numberically or
> sometimes some type of unique_id. Then I store the the decription and
> filename only in the database and use some sort of server-side
> processing to "display" the appropriate image.
>
> Requires much less space in the database and much less strain on the db
> engine to retrieve that much information - especially if you need to do
> the same thing hundreds of times a day.
>

It's not that much different in storage space, and access isn't all the
much different.

I find there can be advantages to storing in the database, as well as
disadvantages. I use them sometimes, and other times not.



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация