TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-30-2008, 06:37 PM   #1 (permalink)
The Visitor
 
Join Date: Jul 2008
Location: North Carolina
Posts: 2
Thanks: 0
bakermx is on a distinguished road
Default Content- type won't change, dynamic image

Hi, I came across an issue while trying to dyamically change the content-type to the right type for an image

Here is show.php
Code:
<?php
include('inc/db.php');

$id = $_GET['id'] ;

   $query = "SELECT imgdata,type FROM pics WHERE id=$id";
   $result = MYSQL_QUERY($query);
   $data = MYSQL_RESULT($result,0,"imgdata");
   $type = MYSQL_RESULT($result,0,"type");
   Header( "Content-type: $type ");
echo $data;

?>
and here is the database structure
Code:
CREATE TABLE pics (
	id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
	type TEXT,
	caption VARCHAR(255),
	albumid INT(10) NOT NULL,
    imgdata LONGBLOB )
Does anyone see any issues with these?

Any Help would be appreciated,
thanks.

- The issue is it outputs the data as text/plain ,
I failed to mention this previously
__________________
"We are told never to cross a bridge until we come to it, but this world is owned by men who have 'crossed bridges' in their imagination far ahead of the crowd."
Send a message via AIM to bakermx Send a message via MSN to bakermx Send a message via Yahoo to bakermx
bakermx is offline  
Reply With Quote
Old 07-31-2008, 09:07 PM   #2 (permalink)
The Contributor
 
buggabill's Avatar
 
Join Date: Jan 2008
Location: Maine, USA
Posts: 92
Thanks: 2
buggabill is on a distinguished road
Default

Are you storing the full type like 'image/jpeg' or something like 'jpeg'?

php Code:
// This would be appropriate for jpegs
header("Content-type: image/jpeg");

If the content type is not correct, the browser may default to text/plain.
__________________
-- Bill
"Why is it drug addicts and computer aficionados are both called users?" -Clifford Stoll
buggabill is offline  
Reply With Quote
Old 07-31-2008, 09:09 PM   #3 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Binary data does not equal plain text. You can't store binary data in a varchar field. Use the blob type instead.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 08-01-2008, 03:12 PM   #4 (permalink)
The Contributor
 
buggabill's Avatar
 
Join Date: Jan 2008
Location: Maine, USA
Posts: 92
Thanks: 2
buggabill is on a distinguished road
Default

Quote:
sql Code:
CREATE TABLE pics (
    id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    type TEXT,
    caption VARCHAR(255),
    albumid INT(10) NOT NULL,
    imgdata LONGBLOB )
They are storing the imgdata in a LONGBLOB field.
__________________
-- Bill
"Why is it drug addicts and computer aficionados are both called users?" -Clifford Stoll
buggabill is offline  
Reply With Quote
Old 08-01-2008, 09:34 PM   #5 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Right. Didn't see that. My bad. However, you should try putting an exit; after that echo, and remove the ?> sign from the end. That way, you're making sure that nothing after that point will be sent to the browser. And, you should use the same content type the image had before inserting it into the database. You're probably doing that already, I assume.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 08-02-2008, 02:22 PM   #6 (permalink)
The Visitor
 
Join Date: Jul 2008
Location: North Carolina
Posts: 2
Thanks: 0
bakermx is on a distinguished road
Default

I'm using image/foo.
It is stored in the database for that particular image so that it always has the right type. I know it's selecting the right content-type also because if I echo out the type instead, i get image/jpeg for a jpeg image and the same with png.
It worked on zymic.com's servers, but not 1and1.com's so it puzzles me.
__________________
"We are told never to cross a bridge until we come to it, but this world is owned by men who have 'crossed bridges' in their imagination far ahead of the crowd."
Send a message via AIM to bakermx Send a message via MSN to bakermx Send a message via Yahoo to bakermx
bakermx is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:19 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design