TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Content- type won't change, dynamic image (http://www.talkphp.com/general/3193-content-type-wont-change-dynamic-image.html)

bakermx 07-30-2008 06:37 PM

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

buggabill 07-31-2008 09:07 PM

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.

xenon 07-31-2008 09:09 PM

Binary data does not equal plain text. You can't store binary data in a varchar field. Use the blob type instead.

buggabill 08-01-2008 03:12 PM

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.

xenon 08-01-2008 09:34 PM

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.

bakermx 08-02-2008 02:22 PM

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.


All times are GMT. The time now is 04:58 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0