FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Images retrives
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Images retrives [message #175969 is a reply to message #175966] Fri, 11 November 2011 14:10 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 11/11/2011 6:45 AM, sritullimilli(at)gmail(dot)com wrote:
> i didn't get the images from mysql database through php script
> i am get this error
>
> <img src='���JFIF
> ...
> plz suggest me
>
> thx&regs

The <img ...> tag requires a resource (typically a file). It looks like
you're trying to send the image itself, which doesn't work.

It's really not had to send an image from a database. Basically you
need code similar to (example code for clarity - no error handling and
untested):

file: showimage.php
<?php
$imageId = intval($_GET['image']));
$link = mysql_connect('server', 'userid', 'password');
$result = mysql_select_db('database');
$result = mysql_query("SELECT image FROM imgtbl WHERE id=$imageId");
$img = mysql_fetch_assoc($result);
header('Content-type: image/jpeg');
header('Content-length: ' . strlen($result['image']));
echo $result('image');
mysql_close($link);
}

You would use this with something like:

<img src="showimg.php?image=5">

In this example the image id is assumed to be an integer. Strings work
also with appropriate changes to the code.

Also the image is assumed to be a jpeg; if you have something else, you
need to change the Content-type line to the appropriate type (i.e.
image/png, etc.).

The Content-length line isn't strictly required, but it will help some
Apache installations to optimize sending the image. It's nice to have.

Hope this helps.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: displaying random images with an appropriate caption
Next Topic: Why fsockopen() generates a Warning on timeout?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 22:53:14 GMT 2024

Total time taken to generate the page: 0.21382 seconds