Jump to content

Recommended Posts

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;
?>

Link to comment
https://forums.phpfreaks.com/topic/133196-help-with-displaying-blob-data/
Share on other sites

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.

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

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?

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.

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.