Ask a Question related to PHP Development, Design and Development.
-
Brian #1
Images from MySQL
Hi All
I'm trying to store images in a MYSQL db, the images at being uploaded
for an external program in a blob field.
I have had a look round and found a few scripts but none of them seem
to work.
All the images are JPG, and what I need to do is at a given point in a HTML
page I want to say "get this image from this table and display it here". The
trouble
I have been having is some of the scripts what to print out the
header("Content-Type: image/jpeg"); but the page will not allow that because
it
already done all its header.
If anybody has some code that does work that would be great ! :)
Brian
Brian Guest
-
Images and mysql
Hi all, I was wondering If anyone knows how to insert images into MySQL and how to retrieve and display the images... VIA php. Thanks -
dynamic images php/mysql
hello! i'm using a mysql database to store product details. i also have an image field declared as blob. i have the products.php page which i... -
Loading images in a movieClip using PHP/MySQL
Loading images in a movieClip using PHP/MySQL I'm just starting to learn Actioncript, so this may be simple. I would be very happy if anyone could... -
Problems with images in MySQL database
I'm having problem with images becoming corrupted after loading them into a MySQL database and extracting them again. I'm pretty sure it's todo with... -
Displaying images from a MySQL Database
Hi I'm have difficulty displaying images that are stored in a MySQL database. I've tried using the odbc.net provider, the ByteFX provider and the... -
J.O. Aho #2
Re: Images from MySQL
Brian wrote:
I have done it in the following manner, first in the page where I have all the> Hi All
>
> I'm trying to store images in a MYSQL db, the images at being uploaded
> for an external program in a blob field.
> I have had a look round and found a few scripts but none of them seem
> to work.
> All the images are JPG, and what I need to do is at a given point in a HTML
> page I want to say "get this image from this table and display it here". The
> trouble
> I have been having is some of the scripts what to print out the
> header("Content-Type: image/jpeg"); but the page will not allow that because
> it
> already done all its header.
> If anybody has some code that does work that would be great ! :)
>
> Brian
>
>
HTML, I have the following link:
<IMG SRC=<?PHP echo "\"img/showimg.php?pic=" . $picid ."&\""; ?>>
and the showimg.php looks something like this:
/* include connect_db() so we make a connection to the database with one
command */
include_once("../libs/db.php");
/* check that we have type and company varibales */
if(strlen($pic)) {
/* connect to database */
$link=connect_db();
/* Do query */
$query="SELECT PictureData, PictureType FROM Pictures WHERE PicID='$picid'
LIMIT 1";
$result=mysql_query($query);
/* save picture to variable */
$picture=mysql_fetch_array($result);
/* close database */
mysql_close($link);
/* send content type and then the data */
header( "Content-type: " . $picture["PictureType"]);
echo $picture["PictureData"];
}
?>
As you see, the picture itself isn't included in the main php page, but has
it's own file, which is loaded each time a picture from the database is
displayed and of course, there aren't any limitation how many pictures at the
time you show (of course long query times and a lagish database can affect this).
//Aho
J.O. Aho Guest
-
ebobnar #3
Re: Images from MySQL
I also had this problem, and I solved it similarly to the way J.O. Aho
did. The problem I am having now is a simple one. If there is no image
found in the database I want to display a "image not found" graphic,
like so:
if (mysql_num_rows($result) < 1)
{
header("Content-type: image/gif");
print("photo_add.gif");
}
else
{
$row = mysql_fetch_array($result);
header("Content-type: " . $row['photo_format']);
print($row['photo_image']);
}
The line "print("photo_add.gif");" is where I am having the problem.
Which is the correct way to phrase this so that photo_add.gif is
returned to the calling file.
The code above is called from another html file like so:
<img src="display_photo.php"></img>
This displays the image fetched from mysql, but not the photo_add.gif
image.
Thanks,
Esoos
ebobnar Guest
-
J.O. Aho #4
Re: Images from MySQL
ebobnar wrote:
$fullPath="photo_add.gif";> I also had this problem, and I solved it similarly to the way J.O. Aho
> did. The problem I am having now is a simple one. If there is no image
> found in the database I want to display a "image not found" graphic,
> like so:
>
> if (mysql_num_rows($result) < 1)
> {
if ($fd = fopen ($fullPath, "rb")) {fpassthru($fd);> header("Content-type: image/gif");
fclose($fd);
}
print is the same as echo and does only handle strings, so to get this to> }
>
> else
> {
> $row = mysql_fetch_array($result);
> header("Content-type: " . $row['photo_format']);
> print($row['photo_image']);
> }
>
> The line "print("photo_add.gif");" is where I am having the problem.
> Which is the correct way to phrase this so that photo_add.gif is
> returned to the calling file.
work, you would need to do the modifications to your code that I have done, I
went a step futher and do only send data if the photo_add.gif is found, in the
case there aren't any picture in the database.
The $fullPath, is from the location from the php file (../img/photo_add.gif)
or an absolute path (/home/user12/pictures/website/photo_add.gif).
//Aho
J.O. Aho Guest



Reply With Quote

