Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #3759

Re: Images retrives

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: Images retrives
Date 2011-11-11 09:10 -0500
Organization A noiseless patient Spider
Message-ID <j9jaci$nr8$1@dont-email.me> (permalink)
References <189232.705.1321011949235.JavaMail.geo-discussion-forums@prdy11>

Show all headers | View raw


On 11/11/2011 6:45 AM, sritullimilli@gmail.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@attglobal.net
==================

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Images retrives sritullimilli@gmail.com - 2011-11-11 03:45 -0800
  Re: Images retrives "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-11-11 13:19 +0100
  Re: Images retrives The Natural Philosopher <tnp@invalid.invalid> - 2011-11-11 13:02 +0000
  Re: Images retrives Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-11 09:10 -0500
  Re: Images retrives Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-12 00:22 +0100
    Re: Images retrives Robert Hairgrove <nobody@hogwash.com> - 2011-11-12 00:34 +0100
      Re: Images retrives Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-12 00:49 +0100
      Re: Images retrives Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-11 19:37 -0500

csiph-web