Forum Moderators: coopster

Message Too Old, No Replies

Php, mysql, image showing problem

php, mysql images , problem

         

farish

9:54 pm on Nov 22, 2005 (gmt 0)

10+ Year Member



Hi ppl.
I have some problem with showing images in my site.

The problem came when i stored the images in mysql datebase, the image field have longblob type. Some of images not displayed. Why?
I can't understand the reason. Because when user visite images original address they view it. Before storing images in mysql datebase the images stored in file system and viewed normally without any problems.

here the code of showing image from mysql datebase.
1. <?php
header("Content-type: image/jpeg");
$imageID=$_GET['imageID'];
mysql_connect("dbhost","dbuser","dbpass");
mysql_select_db("dbname");

$query= "select * from tablename where imageID = $imageID";
$res=mysql_query($query) or die(mysql_error());
$rows=mysql_fetch_array($res);

echo $r ows['Image'];
mysql_close();

?>

2. here from where 1. called.

<html>
<head>
</head>
<body>
<?php
for($i=0;$i<10;$i++)
echo "<img src='1.?imageID=$i'>\n ";
?>
</body>
</html>

all files when stored in file system was viewd normally.
What the problem? please tell me :((((((

tomda

6:09 am on Nov 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



the image field have longblob type

Does this mean that you store the picture data in the database?

You should copy the picture in one of our folder and then in the database, only the WIDTH, the HEIGHT and the NAME is required (so non longblob require).

Usually I generate the picture name by creating an unique variable.
PICTURE NAME - pic_125de6585de14tr3t5
WIDTH - 470
HEIGHT - 450

If you know that your pictures are in a folder called "GDPIC" for example, then the URL is "GDPIC/[PICTURE_NAME].jpg"

You can also create another folder called "GDPIC_SMALL" where you put thumbnail size pictures and the URL is "GDPIC_SMALL/[PICTURE_NAME].jpg"

Hope this help

Twisted Mind

1:02 pm on Nov 25, 2005 (gmt 0)

10+ Year Member



is this a typo? echo $r ows['Image'];

farish

12:44 am on Nov 26, 2005 (gmt 0)

10+ Year Member



2 tomda
yes my images stroed in the datebase. And there is no any folder needed :)))

But the all images don't showen :((( from many ISP's.
My problem that.

tomda

6:51 am on Nov 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Farish,

Then I don't think it is the best way to store pictures in database, you better save your pictures in a folder and store only the "width", "height", "alt" and "name" in the database.

I can't help you much because I don't store picture your way, nonetheless I suspect it is a string conversion problem.
May be when storing data in db, some special characters are changed! Check the code source to see which datas are retrieve and compare it with the original.

Otherwise, tell us a bit more about what you get (warning message, etc.).