Jump to content

Images


unknown gamer

Recommended Posts

Ok, i found this tutorial, It shows you how to upload an image and view it. It works, so i get the code and put it in a php page with html tags, it is in its <?php ?> tag but it says The image “http://gmlink.07x.net/test/individual.php?id=1” cannot be displayed, because it contains errors.the page is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1 DTD/xhtml1-strict.dtd"><html>  <head>	<link rel="stylesheet" type="text/css" href="style.css" />	<title>GMLink - All the Game Maker Websites in one place!</title>  </head>  <body><!--Wrapper--><div id="wrapper"><!--Main border--><div class="boxborder"><div class="bar"></div><!--Logo--><div class="banner"><a href="index.html"><img border="0" src="gmlinklogo692x100.png" width="688" height="100"></a></div><!--Logo end--><div id="menu"><ul><li><a href="index.html">Home</a></li><li><a href="community.php">Community</a></li><li><a href="individual.php">Individual</a></li><li><a href="helpresource.php">Help and Resources</a></li><li><a href="other.php">Other</a></li><li><a href="nongm.php">Non-GM</a></li><li><a href="submit.php">Submit</a></li> </ul></div><!--Main box-->	 <div class="box"><div class="top">Individual</div><div class="text"><center><?phpinclude 'connect.php';$result = mysql_query(sprintf("SELECT * from image WHERE ImageId = %d", $_GET['id']));$row = mysql_fetch_array($result);header(sprintf("Content-type: %s", $row['FileType']));print $row['Image'];?></center></div></div><!--Main box end--><!--Footer--><div class="footer">Footer</div><!--Footer end--><!--Main border end--></div><!--Wrapper end--></div>  </body></html>

it works fine when the php stuff is in a page without html tags.i made a page put the code in, it worked then added <html></html> and i got the same error. I don't understand what is wrong.

Link to comment
Share on other sites

You have to create a seperate file for the image, and then call that file from a HTML page inside an <img /> tag.

Link to comment
Share on other sites

You have to have one page that JUST sends the image data, say image.php:

include 'connect.php';$result = mysql_query(sprintf("SELECT * from image WHERE ImageId = %d", $_GET['id']));$row = mysql_fetch_array($result);header(sprintf("Content-type: %s", $row['FileType']));print $row['Image'];

And the other page just calls that:

<img src="image.php?id=5" />

You can't combine data types.

Link to comment
Share on other sites

I understand what you mean but i can't get it to work... I have image.php:

<?phpinclude 'connect.php';$result = mysql_query(sprintf("SELECT * from image WHERE ImageId='1'));$row = mysql_fetch_array($result);header(sprintf("Content-type: %s", $row['FileType']));?>go to image loader to find all the available id's.

page.php

<?phpinclude 'image.php';print "<img src='$row[Image]' />";?>

I am totally confused by my code.

Link to comment
Share on other sites

Not quite... think of the image.php file, in this case, as the actual image. Just as if it were a .gif or .png file.So you actually call that file from inside the image tags.So, make image.php look JUST like this - nothing else

<?phpinclude 'connect.php';$result = mysql_query(sprintf("SELECT * from image WHERE ImageId = %d", $_GET['id']));$row = mysql_fetch_array($result);header(sprintf("Content-type: %s", $row['FileType']));print $row['Image'];?>

And then your other page will look something like

...<div class="text"><center><img src="image.php?id=<?php echo $_GET['id']; ?>" /></center></div>...

Link to comment
Share on other sites

I am totally confused by my code.
Basically, your server/browser don't care what's in the "src" attribute of your image tag. A request is simply sent saying "Hey you! I need this image!", at which point the server sends a response back saying "OK, sure, here it is!". So if you use a PHP file in your image source, a request is sent with that information. When that request gets to your server, it basically says "OK, let me run this script and whatever its output is I'll send back to you". So if your script is set up to output image data, the image shows up. But if you put anything else in your image.php script, it tries to send data other than just an image, thus throwing an error.I don't know if I'm explaining that right. I hope it made sense.
Link to comment
Share on other sites

You change them to what I wrote in my last post.... copy and paste even! It should work :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...