mistertylersmith Posted March 15, 2008 Share Posted March 15, 2008 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? Quote Link to comment Share on other sites More sharing options...
Nhoj Posted March 15, 2008 Share Posted March 15, 2008 Try changing: header('Content-type: "type/jpeg"'); To: header('Content-type: image/jpeg'); Quote Link to comment Share on other sites More sharing options...
mistertylersmith Posted March 16, 2008 Author Share Posted March 16, 2008 nope, that wasnt it =\ Quote Link to comment Share on other sites More sharing options...
unsider Posted March 16, 2008 Share Posted March 16, 2008 I don't see any error, I'll keep looking, but it looks as if everything would work properly. Quote Link to comment Share on other sites More sharing options...
mistertylersmith Posted March 16, 2008 Author Share Posted March 16, 2008 i think i solved it.. i changed the header to 'Content-type: $mime' and it works. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.