andrew_ww Posted November 18, 2008 Share Posted November 18, 2008 Hello, I have created a page that uploads a jpeg to a mysql database. This works okay. I am now having trouble getting the data to display as an image. After conducting some research I understand that you must use two webpages to display this type of information. To this effect I have create 2 pages (image.php and getdata.php). I will place the code at the bottom of the page. The actual problem is that the pages will not display the image. All I get is a red cross. The other error check produces this: array(0) { } Any suggestions as to how I can get this to work. (I'm fully aware that the better way to display images is to store the path, however I'm doing this for a specific purpose) Here is the code image.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <img src="getdata.php?id=22" /> </body> </html> <?php // display.php error_reporting(E_ALL); var_dump($_GET); ?> ----------------------------------------------------------------------- getdata.php <?php // SEE AS MUCH INFORMATION AS WE CAN! error_reporting(E_ALL); // CONNECT TO DB (HOW DO WE KNOW THIS IS WORKING?) require_once('connections/hector_mysql.php'); // GET ARG FROM URL - NOTE WE ASSUME IT IS NUMERIC ONLY $id = $_GET["id"]; // CONSTRUCT AND EXECUTE A QUERY, RETRIEVE ALL COLUMNS USING * $query = "SELECT * FROM tbl_image_upload WHERE image_id=$id LIMIT 1"; if (!$result = mysql_query($query)) { echo "<br />ERROR IN $query \n"; echo "<br /> "; echo mysql_errno(); echo mysql_error(); var_dump($_GET); die(); } // GET ACCESS TO LOCAL VARIABLES $row = mysql_fetch_assoc($result); $data = $row["image"]; $type = $row["image_type"]; // SPEW THE IMAGE Header( "Content-type: $type"); Header( "Content-type: image/pjpeg"); echo $data; exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/133196-help-with-displaying-blob-data/ Share on other sites More sharing options...
premiso Posted November 18, 2008 Share Posted November 18, 2008 I think your header is wrong. Header( "Content-type: $type"); Header( "Content-type: image/jpg"); echo $data; exit; ?> Another way to check is to browse to the actual image page and make sure there are no errors on the getimage.php page. If there is it would show up there or if not it should show the image. Quote Link to comment https://forums.phpfreaks.com/topic/133196-help-with-displaying-blob-data/#findComment-692752 Share on other sites More sharing options...
andrew_ww Posted November 18, 2008 Author Share Posted November 18, 2008 Tried your suggestion however the same problem remains. Quote Link to comment https://forums.phpfreaks.com/topic/133196-help-with-displaying-blob-data/#findComment-692753 Share on other sites More sharing options...
premiso Posted November 18, 2008 Share Posted November 18, 2008 Are you sure that getdata.php?id=22 does not display an error. Given that you have error reporting turned on I would check that the page is actually pulling the data from MySQL and is not displaying any text that it shouldn't, as that would throw off the image and have it display the red X Quote Link to comment https://forums.phpfreaks.com/topic/133196-help-with-displaying-blob-data/#findComment-692756 Share on other sites More sharing options...
PFMaBiSmAd Posted November 18, 2008 Share Posted November 18, 2008 If the var_dump() inside of getdata.php is giving the empty array and you actually have <img src="getdata.php?id=22" /> in your main page, then either some code in getdata.php or hector_mysql.php is overwriting the GET array or register_globals are on. What is in hector_mysql.php and what does a phpinfo() statement show for register_globals? Quote Link to comment https://forums.phpfreaks.com/topic/133196-help-with-displaying-blob-data/#findComment-692760 Share on other sites More sharing options...
andrew_ww Posted November 18, 2008 Author Share Posted November 18, 2008 I've looked at the output og phpinfo() and it was: register_globals Off Off Quote Link to comment https://forums.phpfreaks.com/topic/133196-help-with-displaying-blob-data/#findComment-692777 Share on other sites More sharing options...
premiso Posted November 18, 2008 Share Posted November 18, 2008 To elaborate on some stuff, did you try just calling the getdata.php?id=22 page and see what displays there? View the source and see what shows up. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <img src="getdata.php?id=22" /> </body> </html> <?php // display.php error_reporting(E_ALL); var_dump($_GET); ?> That var_dump will be empty, cause you make a remote call out the getdata.php page. Doing this you set the get data inside the image tag. Therefore it would return empty. Check out that http://www.yoursite.com/getdata.php?id=22 page and see if there are any errors and view the source. If there are errors that is the issue. If there are not then we will continue from there. Quote Link to comment https://forums.phpfreaks.com/topic/133196-help-with-displaying-blob-data/#findComment-692784 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.