473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

image from MySQL database not working

<?php
include 'dbinc.php';
$result = mysql_query("SELECT image,mime_type FROM photos WHERE
image_id=".intval($_GET['id']), $link) or die("MyErr:".mysql_error());
if ($row = mysql_fetch_assoc($result)) {
$ext=array('image/jpeg'=>'jpg','image/gif'=>'gif','image/png'=>'png','image/x-png'=>'png');
header("Expires: Mon, 26 Jul 2030 05:00:00 GMT");
header("Content-Type: $row[mime_type]");
header("Content-Disposition: inline;
$_GET[id].".$ext[$row['mime_type']]);
echo "\r\n".stripslashes($row['image']);
}
mysql_free_result($result);
?>

what am I doing wrong? I don't get an image. I've seen thumbnail stuff. I
don't want a thumbnail (that code didn't work either for some reason).
Apr 15 '06 #1
4 1576
Jim Michaels wrote:
<?php
include 'dbinc.php';
$result = mysql_query("SELECT image,mime_type FROM photos WHERE
image_id=".intval($_GET['id']), $link) or die("MyErr:".mysql_error());
if ($row = mysql_fetch_assoc($result)) {
$ext=array('image/jpeg'=>'jpg','image/gif'=>'gif','image/png'=>'png','image/x-png'=>'png');
header("Expires: Mon, 26 Jul 2030 05:00:00 GMT");
header("Content-Type: $row[mime_type]");
header("Content-Disposition: inline;
$_GET[id].".$ext[$row['mime_type']]);
echo "\r\n".stripslashes($row['image']);
}
mysql_free_result($result);
?>

what am I doing wrong? I don't get an image. I've seen thumbnail stuff. I
don't want a thumbnail (that code didn't work either for some reason).


I have no idea what you did wrong. What do you get? What's in the source?
What's in the database row?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 16 '06 #2
hi,
I think the second header call needs quotes for 'mime_type'

hope it helps

Apr 16 '06 #3

"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:Df******************************@comcast.com. ..
Jim Michaels wrote:
<?php
include 'dbinc.php';
$result = mysql_query("SELECT image,mime_type FROM photos WHERE
image_id=".intval($_GET['id']), $link) or die("MyErr:".mysql_error());
if ($row = mysql_fetch_assoc($result)) {

$ext=array('image/jpeg'=>'jpg','image/gif'=>'gif','image/png'=>'png','image/x-png'=>'png');
header("Expires: Mon, 26 Jul 2030 05:00:00 GMT");
header("Content-Type: $row[mime_type]");
header("Content-Disposition: inline;
$_GET[id].".$ext[$row['mime_type']]);
echo "\r\n".stripslashes($row['image']);
}
mysql_free_result($result);
?>

what am I doing wrong? I don't get an image. I've seen thumbnail stuff.
I don't want a thumbnail (that code didn't work either for some reason).


I have no idea what you did wrong. What do you get? What's in the
source? What's in the database row?


found the problem. stripslashes and the newlines turned out to be a bug. so
echo "\r\n".stripslashes($row['image']);
became
echo $row['image'];

and the problem I was having with error messages about headers already being
sent came because dbinc.php had some blank lines after the ?>
:-/
well, at least I found it.
The Expires header isn't necessary. I should probably take it out. The ;
filename after inline isn't necessary either. (maybe it make things easier
for the cache, but I disabled the page cache via headers elsewhere)

I found another method would be to use imagecreatefromstring() and that
somehow you can detect the mime-type from that rather than storing it in the
db, butyou also have the problem that if the image is hefty (1MB), that
function will consume 16MB of RAM. combined with the use of another common
function, it would take a total of 32MB. PHP would then die. this function
is a memory hog (why?). Then you use imagejpeg().

I *thought* you were supposed to send a newline to signify end of headers
before sending image data. It seems I was wrong. I got the right size
image placeholder, but no image. weird. guess I'd have to look at the
format to see why that is. (?) maybe PHP does some of this for me
automatically or something behind the scenes.
From the command-line I discovered after I sent out headers, imagejpeg()
secretly inserts \r\n into the image data. I had to get out my editor to
binary-delete the first 2 bytes for the image to come out right. my old
copy of TSE 2.8 is still good for a few things. :-)

Apr 17 '06 #4

"foaud167" <f.*******@gmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
hi,
I think the second header call needs quotes for 'mime_type'
that would cause an error.


hope it helps

Apr 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jason Murry | last post by:
I have a camera system (Axis) which stores JPG via FTP 1-10fps. There is also a motion jpg live stream. I am trying to store these images either in JPG or in video format so they can be...
5
by: Alper Adatoz | last post by:
Hi, i have a little problem. i hope u guys give me a clear solution (: db: mssql i just want to put jpeg file to the image field at the mssql db. and after that i want to call it back..
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
7
by: theonlydrayk | last post by:
the script that show image is : <?php include('dbinfo.inc.php'); mysql_connect($localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query =...
3
by: Christopher Mouton | last post by:
We regularly make drive images of our entire server and store it at a backup site. To be honest I have never fully understood how the imaging programs deal with open files. My question is will the...
10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
7
by: eholz1 | last post by:
Hello Group, Perhaps you can help me. I have a mysql db, that holds images. Images are encoded using base64_decode/encode, etc. Image data seems fine. I have a view.php page that is supposed...
8
tharden3
by: tharden3 | last post by:
Hey Bytes, The website I'm working on is coming along just fine, and I'd like to thank all of you PHP folks who have been helping me out. I'm almost done with the coding! I'm trying to get the...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.