Images showing up in code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jfavelle
Forum Newbie
Posts: 8
Joined: Wed Jan 27, 2010 1:24 pm

Images showing up in code

Post by Jfavelle »

Hi

My images aren't loading, instead i am just getting them displayed as code like this:

Code: Select all

 
ÿØÿà\0JFIF\0::\0\0ÿáPExif\0\0II*\0\0\0\0\0\0 \0\0\0n\0\0\0\0\0\0\0Ž\0\0\0\0 \0\0\0¦\0\0\01\0 \0\0\0²\0\0\02\0\0\0\0Ò\0\0\0\0\0\0\0\0\0\0i‡\0\0\0\0\0\0¥Ä\0"\0\0æ\0\0\0\0\0\0\0OLYMPUS DIGITAL CAMERA \0OLYMPUS IMAGING CORP. \0FE210,X775\01.0 \02009:09:16 16:56:26\0PrintIM\00300\0\0%\0\0\0\0\0\0\0\0\0î\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0 \0\0\0\0\0 \06\0\0 \0\0\0\0\0 \0\0\0\0\0\0N\0\0\0r\0\0 \0Æ\0\0\0\0\0\0ÿ\0\0\0ƒ\0\0\0ƒ\0\0\0ƒ\0\0\0ƒ\0\0\0ƒ\0\0\0€€€\0€\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0 \0\0\0\0 è\0\0 \0\0\0\0 \0\0\0\0\0\0\0ÿ\0\0\0ƒ\0\0\0ƒ\0\0\0ƒ\0\0\0€\0\0\0\0\0\0\0\0 \0\0''\0\0 \0\0''\0\0—\0\0''\0\0°\0\0''\0\0\0\0''\0\0^\0\0''\0\0‹\0\0\0''\0\0Ë\0\0''\0\0å\0\0''\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0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\0\0\0!\0ü\0\0\0X\0\0\0"\0J\0\0T\0\0\0#\02\0\0ž\0\0\0$\0B\0\0\0Ð \0\0\0%\06\0\0\0 \0\0\0&\0ö\0\0\0H \0\0\0''\0Z\0\0\0> \0\0\0(\0Ž\0\0˜ \0\0\0)\0~\0\0\0& \0\0\0\0\0\01.005\0\0\0\0\0\0\0\0\0\0\0\0\0d\0\0\0d\0\0\0ú\0\0è\0\0¨ÿáþ|þ¥ÿÚþtþD4334\0OLYMPUS DIGITAL CAMERA \0\0\0\0 \0\0\06\0\0\0\0\0\0OK\0\0\0\0\0\0OK\0\0\0\0\0\0OK\0\0\0\0\0\0OK\0\0\0\0\0\0OK\0\0\0\0\0\0OK\0\0\0\0\0\0OK\0\0
Help me:)
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Images showing up in code

Post by social_experiment »

Please paste the code that you are using
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Jfavelle
Forum Newbie
Posts: 8
Joined: Wed Jan 27, 2010 1:24 pm

Re: Images showing up in code

Post by Jfavelle »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Here is the code that selects the image from the db:

Code: Select all

<?php
     // some basic sanity checks
     if(isset($_GET['image_id']) && is_numeric($_GET['image_id'])) {
         //connect to the db
         $link = mysql_connect("localhost", "", "") or die("Could not connect: " . mysql_error());
  
         // select our database
         mysql_select_db("people") or die(mysql_error());
           
           // get the image from the db
        $sql = "SELECT Picture FROM people WHERE ID=" . $_GET['image_id'];
        
         // the result of the query
         $result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
  
         // set the header for the image
         header("Content-type: image/jpeg");
                  echo mysql_result($result, 0);
  
        // close the db link
         mysql_close($link);
     }
     else {
         echo 'Please use a real id number';
     }
 ?>
And this is the code that displays it

Code: Select all

$fldPicture = $db->f("r_Picture");
 
if(strlen($fldPicture))
      {
        $tpl->set_var("Image", "<img style='float:right' width='80px' height='80px' src='image.php?image_id=" . $fldID_ID . "' alt='Photo' />");
      }
      else
      {
        $tpl->set_var("Image", "");
 
Thanks Greatly!


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Images showing up in code

Post by pickle »

Is that code you posted in the original post the source code from the entire page? What's happening is the browser isn't realizing how to display the data it's receiving. That happens because the headers sent don't match the data. I see you're sending the Content-type header, but there must be other headers being sent earlier. Do you have any spaces at the beginning of the file, or in any included files?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Jfavelle
Forum Newbie
Posts: 8
Joined: Wed Jan 27, 2010 1:24 pm

Re: Images showing up in code

Post by Jfavelle »

The code I am getting in the original post is what when i go to the img src from the image tag: i.e image.php?image_id=181. I have a file which imports from that php and the headers I have in that are

Code: Select all

//-------------------------------
// Verify user's security level and redirect to login page if needed
//-------------------------------
 
function check_security($security_level)
{
  global $PeopleRights;
  if(!session_is_registered("PeopleID"))
  {
    header("Location: refLogin.php?querystring=" . urlencode(getenv("QUERY_STRING")) . "&ret_page=" . urlencode(getenv("PATH_INFO")));
    exit;
  }
  else
    if(!session_is_registered("PeopleRights") || $PeopleRights < $security_level)
    {
      header("Location: screeningLogin.php?querystring=" . urlencode(getenv("QUERY_STRING")) . "&ret_page=" . urlencode(getenv("PATH_INFO")));
      exit;
    }
}
But that shouldn't conflict with the image should it?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Images showing up in code

Post by pickle »

So the source code of the page is something like:

Code: Select all

<img src = "ÿØÿà\0JFIF\0 etc..." />
??
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Jfavelle
Forum Newbie
Posts: 8
Joined: Wed Jan 27, 2010 1:24 pm

Re: Images showing up in code

Post by Jfavelle »

No, sorry when I went to http://westnet/intranet/people/image.php?image_id=181, that was what was displaying in the browser. I just went there again and it is now

<img src="http://westnet/intranet/people/image.php?image_id=181" />

... don't ask me.

The image still isn't displaying though, I am saving it to the data base as a blob could that possibly have anything to do with it.

Thanks so much!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Images showing up in code

Post by pickle »

Possibly. If the image is larger than 64K, it won't fit in a BLOB & would be truncated. That might be what you're seeing.

If you've got Firefox, install Firebug & go to: http://westnet/intranet/people/image.php?image_id=181 . I think Firebug gives you a chance to see the headers that are sent.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Jfavelle
Forum Newbie
Posts: 8
Joined: Wed Jan 27, 2010 1:24 pm

Re: Images showing up in code

Post by Jfavelle »

the images are smaller then 64 k, it doesn't matter. The header is showing up as well.

Please, I need you guys don't let me down!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Images showing up in code

Post by AbraCadaver »

Try:

Code: Select all

echo stripslashes(mysql_result($result, 0));
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply