englishcodemonkey Posted July 19, 2008 Share Posted July 19, 2008 Heres my code: <html> <head> <title>Untitled Document</title> </head> <body> <?php header("content-type:image/jpg"); require_once('conn.php'); $q = "SELECT image from images where imgid='2'"; $r = @mysqli_query ($dbc, $q); $row = mysqli_fetch_assoc($r); $news = imagecreatefromstring($row['image']); $final = imagejpeg($news); echo $final; ?> </body> </html> The error i'm getting is: Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/e/s/jesspomfret/html/showimage2.php:6) in /home/content/j/e/s/jesspomfret/html/showimage2.php on line 6 And then the binary from my image blob shows?? I've read that this is the whitespace problem but i can't see where my problem is?? Any ideas? Thanks guys Link to comment https://forums.phpfreaks.com/topic/115624-cannot-modify-header-errror/ Share on other sites More sharing options...
ignace Posted July 19, 2008 Share Posted July 19, 2008 you are in serious trouble: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Link to comment https://forums.phpfreaks.com/topic/115624-cannot-modify-header-errror/#findComment-594377 Share on other sites More sharing options...
englishcodemonkey Posted July 19, 2008 Author Share Posted July 19, 2008 After reading that i have changed my code to: <?php header("content-type:image/jpeg"); require_once('conn.php'); ?> <html> <head> <title>Untitled Document</title> </head> <body> <?php $q = "SELECT image from images where imgid='2'"; $r = @mysqli_query ($dbc, $q); $row = mysqli_fetch_assoc($r); $news = imagecreatefromstring($row['image']); $final = imagejpeg($news); echo $final; ?> </body> </html> I still just see the binary??Why won't my image show up?? Link to comment https://forums.phpfreaks.com/topic/115624-cannot-modify-header-errror/#findComment-594380 Share on other sites More sharing options...
maexus Posted July 19, 2008 Share Posted July 19, 2008 You are declaring the document as a jpeg yet you are trying to output text. That doesn't make any sense. Link to comment https://forums.phpfreaks.com/topic/115624-cannot-modify-header-errror/#findComment-594382 Share on other sites More sharing options...
englishcodemonkey Posted July 19, 2008 Author Share Posted July 19, 2008 How to i modify this to display the image?? <img src="$final"/>?? would that work This is my first time trying to use php to display images so thanks for your help! Link to comment https://forums.phpfreaks.com/topic/115624-cannot-modify-header-errror/#findComment-594386 Share on other sites More sharing options...
ignace Posted July 19, 2008 Share Posted July 19, 2008 This is what you are looking for: <img src="image.php?file=2" width="64" height="64" /> Link to comment https://forums.phpfreaks.com/topic/115624-cannot-modify-header-errror/#findComment-594390 Share on other sites More sharing options...
englishcodemonkey Posted July 19, 2008 Author Share Posted July 19, 2008 <img src="image.php?file=2" width="64" height="64" /> OK whats the "image.php?file=2" mean?? Do i place this line of code into my php file or do i place it in a html file and then direct it to my php file?? I apologise for being so confused at this point! Link to comment https://forums.phpfreaks.com/topic/115624-cannot-modify-header-errror/#findComment-594394 Share on other sites More sharing options...
wildteen88 Posted July 19, 2008 Share Posted July 19, 2008 You cannot display binary data/html at the same time. In order to display an image in html it has to be done through the img tag. As you have your images stored in the database, you cannot just echo the image binary data in your page and expect the image to load. Link to comment https://forums.phpfreaks.com/topic/115624-cannot-modify-header-errror/#findComment-594397 Share on other sites More sharing options...
englishcodemonkey Posted July 19, 2008 Author Share Posted July 19, 2008 Ok so how do i have to do it please? I don't want the binary just the image? Link to comment https://forums.phpfreaks.com/topic/115624-cannot-modify-header-errror/#findComment-594400 Share on other sites More sharing options...
wildteen88 Posted July 19, 2008 Share Posted July 19, 2008 EDIT: Thread Locked Do not post multiple topics for the same question. You have another thread here Link to comment https://forums.phpfreaks.com/topic/115624-cannot-modify-header-errror/#findComment-594403 Share on other sites More sharing options...
Recommended Posts