[thelist] php/MySQL, images and valid HTML output...
Joe Crawford
jcrawford at avencom.com
Wed Mar 28 11:28:06 CST 2001
on 3/28/01 9:15 AM, John Corry at webshot at neoncowboy.com wrote:
> Say you are creating a bunch of pages from content stored in a MySQL db.
> Some of the content (or even most of it) is images. To output valid HTML you
> have to include height and width attributes in the img tag.
>
> In my example, I'm storing paths to the images that I can retrieve to write
> into the src attribute of the img tag. My best thought is to also store the
> h & w values, and write them into their appropriate attributes. Is there a
> better way?
>
> I briefly considered the remote possibility that one might use the db
> content to create image objects, rather than img tags...and then use JS to
> write the tags...and generate the h & w attributes on the fly, but that
> seemed way to complicated and daunting when compared to just putting the h &
> w in the db.
I've not put image data in a database yet -- but this is a code snippet I've
used to put heights and widths in on the fly...
<?php
// $i is the path to the image, get it however you like.
if (is_file($i)) {
$my_image_file = $i;
$size = GetImageSize($my_image_file); ?>
<IMG SRC="<?php echo $my_image_file; ?>" <?php echo $size[3]; ?> ALT=""
BORDER="5">
<?php } else { ?>
something wrong here.<BR><BR>try going
<STRONG>back</STRONG><BR><BR>if all else fails, notify the <A
HREF="/feedback/">webmaster</A>.
<?php } ?>
Check http://php.net/manual/en/function.getimagesize.php for more on that
function. I have no idea if the function will work on output from a
database. You might try a test and see if that works?
Either that, or yes, you could store the height and width in the database.
- Joe <http://artlung.com/>
--
Joe Crawford |||||||||||||| mailto:jcrawford at avencom.com
|||||||||||||||||||||||| http://www.avencom.com
||||||||||||||||||||||||||| Avencom: Set Your Sites Higher
More information about the thelist
mailing list