Jump to content

Strange Problem Occurring


mistertylersmith

Recommended Posts

PHP version : 5.2.3

MySQL version : 5.0.41-community-nt

Browser : Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12)

 

Hi,

I'm trying to write a simple script that uploads an image file into a mysql table and makes use of the BLOB type.

As far as I understand, you need 3 files to make this happen: 1 to upload, 2 to 'create' the image from the database, and 3 to actually display the image.  I can get the image to upload correctly, but when I try to 'create' the image from the database, my browser prompts me to open or save the script that is that used to create the image from the database blob.  Here is the code I have for the table and the image create:

 

CREATE TABLE `images` (
`img_id` int( 11 ) NOT NULL AUTO_INCREMENT ,
`img_type` varchar( 20 ) default NULL ,
`img_data` mediumblob,
`img_size` int( 11 ) default NULL ,
PRIMARY KEY ( `img_id` )
) ENGINE = InnoDB

 

<?php 
// database connection
mysql_connect("localhost","root","notmypassword") OR DIE (mysql_error());

// select the db
mysql_select_db ("testing_zone") OR DIE ("Unable to select db".mysql_error());

//variables
$id = $_GET['id'];
if(isset($_GET['id']) && is_numeric($_GET['id'])) {
// get the image from the db
$sql = 'SELECT * FROM `images` WHERE `img_id` = "'.$id.'"';

// the result of the query
$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
$row = mysql_fetch_array($result);
// set the header for the image
header('Content-type: "type/jpeg"');
echo $row['img_data'];
}
else {
echo 'Please use a real id number';
}
?>

 

does anyone have any idea why im having this problem?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.