Forum Moderators: coopster

Message Too Old, No Replies

image is shown as text instead of image

         

kristof_v

9:52 pm on Oct 26, 2005 (gmt 0)

10+ Year Member



hi,

the website consists of tables.
all the content comes into one <td> with php include() as you can see here:

<?php
echo '<br />';
if (isset($_GET['page']) && $_GET['page']!= ''){
include($_GET['page']);
}
else
include('home.htm');
?>

I also created the following file to get the pictures from the database and show them as thumbnails:

<?php
$dir = 'images/albums/brasschaat/';

$conn = mysql_connect("localhost","?","?");
mysql_select_db("?",$conn);
$query = 'select id, naam from foto_brasschaat';
$result = mysql_query($query,$conn);

$teller = 0;

while ($row = mysql_fetch_array($result)) {
if ($teller%5 == 0) {
echo '</tr></table><table><tr align="left">';
}
echo '<td align="left"><img src="' . $dir . $row['naam'] . '" width="50" height="50" onClick="maximize(\'' .$row['naam']. '\')" style="border: 1px dashed white;" align="left" /></td>';

$teller = $teller + 1;
}
?>

this is the javascript function maximize:
<script language="javascript">
function maximize(naam) {
alert("naam = " +naam);
window.location = 'http://example.com/view_image.php?name='+naam;
}
</script>

and this is view_image.php which is called from the javascript function to show the image in its original format in <td> when clicked on the thumbnail:

<?php
ob_start();

if(isset($_GET['name'])) {
header("Content-type: image/jpeg");
header('location:http://example.com/index.php?page=images/albums/brasschaat/' . $_GET['name'] . '.jpg');
}
else
{
echo 'error';
}
?>

this has as a result that the image is shown in <td> as i wished, but in text format and not in image format.

can anyone help me to show the image in image format in the <td>?

grtz kristof

[edited by: ergophobe at 8:34 pm (utc) on Oct. 27, 2005]
[edit reason] URL exemplified [/edit]

lobo235

10:41 pm on Oct 27, 2005 (gmt 0)

10+ Year Member



You cannot set the content type and then do header( 'Location: blah.html' ); because the content-type does not carry over to the next page. You will need to set the content-type in the file your are redirecting to. In your case this would be in the index.php referenced in your header( 'Location: ' ); call.

kristof_v

11:23 pm on Oct 27, 2005 (gmt 0)

10+ Year Member



yes i thought of that.
but i made a workaround.

when clicked on a thumbnail, a .htm file is dynamically created by php with the <img> tag.

this works fine :)

thx for replies,
grtz kristof