473,398 Members | 2,368 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,398 software developers and data experts.

display image stored in BLOB field using php

134 100+
hi

i have stored user profile images in an BLOB field.,

and need to display it as an thumbnail image in their profile page.,

and i searched through the net and got the result using header functions as

follows.,

Expand|Select|Wrap|Line Numbers
  1. <?
  2. include 'config.php';
  3.  
  4. function displayimage($data)
  5. {
  6.     $type='image/pjpeg';
  7.  
  8.     Header( "Content-type: $type");    
  9.  
  10.     $size = 150;  // new image width
  11.     $src = imagecreatefromstring($data); 
  12.     $width = imagesx($src);
  13.     $height = imagesy($src);
  14.     $aspect_ratio = $height/$width;
  15.  
  16.     if ($width <= $size) {
  17.       $new_w = $width;
  18.       $new_h = $height;
  19.     } else {
  20.       $new_w = $size;
  21.       $new_h = abs($new_w * $aspect_ratio);
  22.     }
  23.  
  24.     $img = imagecreatetruecolor($new_w,$new_h); 
  25.     imagecopyresized($img,$src,0,0,0,0,$new_w,$new_h,$width,$height);
  26.  
  27.       imagejpeg($img); 
  28.  
  29.      imagedestroy($img); 
  30. }
  31.  
  32. //displaying image from database
  33.  
  34. $query = "select content from photo where pid = 1";
  35. $result = @mysql_query($query);
  36.  
  37. $data = @mysql_result($result,0,"content");
  38.  
  39. displayimage($data);
  40.  
  41. ?>
  42.  
which results in displaying a perfect thumb image..

but when i try to display the image after some other execution of php code., i,e

for example if i insert an tag
Expand|Select|Wrap|Line Numbers
  1. <? echo "image here";?>
  2.  
before displaying the image.,

i get an error message

"Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs...........(the line where the echo statement comes"

how to get over this...

any ideas..

regards
vijay
Mar 23 '10 #1
6 8465
Markus
6,050 Expert 4TB
You simply cannot do that. When you send binary image data to the browser, that's all it can take. What are you trying to accomplish here?
Mar 23 '10 #2
vjayis
134 100+
i just want to display the image stored in my database(BLOB) as the profile picture for the users..
Mar 23 '10 #3
Dormilich
8,658 Expert Mod 8TB
do you know how HTML displays pictures?
Mar 23 '10 #4
vjayis
134 100+
yes ofcourse., it displays images using <img> tag....
Mar 23 '10 #5
vjayis
134 100+
got your way..

sent the variable inside the src tag and displayed the image by printing the image in image.php page...
Expand|Select|Wrap|Line Numbers
  1. <img src="image.php?data=1" />
  2.  
Mar 23 '10 #6
What Dormilich was actually trying to say is HTML uses something like inline frames to display the images the source attribute doesn't actually mean the actual source data. You would need to use a PHP file to display the images using GET variables then just place the path to the PHP file.
Mar 23 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Kevin | last post by:
Hi all, Assuming I have stored the binary data of an image file in a blob field of a table, how can I display it as an image in a web page? I found some instructions on the web, such as ...
2
by: Bob | last post by:
Hello: I've tried showing an image field from an MS SQL Server 2000 image field on an ASP page but All I get is this http://http://new.confectioneryhouse.com/glutenfree/about.asp I added the...
2
by: zhaounknown | last post by:
I have a field set to Image data type, and store a long string(possible other objects)into it with size 5663, and returned with 5663+28 bytes. These strings wil be deserialized after retrieving....
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...
2
by: Olav Tollefsen | last post by:
How can I display photo images stored in a SQL Server 2000 databases in a DataList or DataGrid without having to write the images to files first? Olav
2
by: Chucker | last post by:
Hi Community, I think I can store Binary Data in SQL Server but when I try to retrieve it, I always only get one byte. I think I stored my Binary Data in SQL Server in a Colum of Type Image....
2
by: RedSouljaz | last post by:
Hi, How to display image that was saved in database ms sql server 2000 into picture box. The field type that I use in database is Images I can save to database but cannot show from database. ...
4
by: C CORDON | last post by:
I have an image stored in a SQL DB how can I display it in a control on a Windows Form? TIA!
8
by: yoyo | last post by:
Ok, I think I just may be a moron, but where the heck are the Image extenders found? I've look all around, tried all the DB2 cd's I have, are they installed by default somewhere? Which install...
0
by: Big George | last post by:
Hello, I'm trying to save a jpg file of 300KB as a BLOB field in an Oracle 10g Database. If I try to call a Stored Procedure, it fails. If I use CommandText with SQL sentence, it success. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.