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? Link to comment https://forums.phpfreaks.com/topic/96319-strange-problem-occurring/ 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'); Link to comment https://forums.phpfreaks.com/topic/96319-strange-problem-occurring/#findComment-493063 Share on other sites More sharing options...
mistertylersmith Posted March 16, 2008 Author Share Posted March 16, 2008 nope, that wasnt it =\ Link to comment https://forums.phpfreaks.com/topic/96319-strange-problem-occurring/#findComment-493221 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. Link to comment https://forums.phpfreaks.com/topic/96319-strange-problem-occurring/#findComment-493224 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. Link to comment https://forums.phpfreaks.com/topic/96319-strange-problem-occurring/#findComment-493231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.