...

View Full Version : php image display



davidmerson
03-02-2008, 01:17 PM
hey, i have a small problem which im sure is very simple to work out, i just cant seem to figure it out! i have a page which can let you upload an image to a mysql database.

at the moment my code is displaying a link which you can download the image from, buy using :


<a href="download.php?id=<?=$id;?>"><?=$name;?></a> <br>


but i want to be able to view the image in the browser instead of having a link, here is my code i have:


<?

if(isset($_GET['id']))

{

include 'config.php';

include 'opendb.php';



$id = $_GET['id'];

$query = "SELECT name, type, size FROM upload WHERE id = '$id'";

$result = mysql_query($query) or die('Error, query failed');

list($name, $type, $size) = mysql_fetch_array($result);



header("Content-Disposition: attachment; filename=$name");

header("Content-length: $size");

header("Content-type: $type");

echo $content;



include 'closedb.php';

exit;

}



?>

<html>

<head>

<title>Download File From MySQL</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>



<body>

<?

include 'config.php';

include 'opendb.php';



$query = "SELECT id, name, customer FROM upload";

$result = mysql_query($query) or die('Error, query failed');

if(mysql_num_rows($result) == 0)

{

echo "Database is empty <br>";

}

else

{

while(list($id, $name, $customer) = mysql_fetch_array($result))

{
echo "<td>" . ($customer) . "</td><br />";

?>

<a href="download.php?id=<?=$id;?>"><?=$name;?></a> <br>

<?

}


}

include 'closedb.php';

?>

</body>

</html>


if anyone could help me i would appreciate it so much!! thanks
David

abduraooft
03-02-2008, 01:24 PM
<img src="<?php echo $name;?>" />
Assuming $name gets the name of the image-file(including extension).

digitalfiz
03-02-2008, 01:28 PM
remove the Content-Disposition header and it will display instead of force download.

davidmerson
03-04-2008, 01:24 PM
cheers guys for both your help!!! i have now removed the header with forced the download, so now when you click on the text link the image displays straight away.

i have a couple more questions that if you could answer would be great, i was wondering how to have a small thumbnail image you can click on instead of the text link??

and also is there any way that when you click the link at the moment the image is displayed in another browser window???

any help would again me much appreciated, and thatnks again for your help already!!

David

peteyb383
03-05-2008, 03:09 AM
In order to get a thumbnail image and link from it, you have to set the height and width of the image, and wrap the link around it...



<a href="download.php?id=<?=$id;?>">
<img height="80" width="125" src="<?php echo $name;?>" />
</a>


You can set 125 and 80 to anything you want for a thumbnail size..

As for your second question, if you insert a

target="_blank"
into the link tag, it will open in a new window.



<a href="download.php?id=<?=$id;?>" target="_blank">
<img height="80" width="125" src="<?php echo $name;?>" />
</a>

davidmerson
03-05-2008, 04:25 PM
thank you very much for your response, that code is bringing up thumbnails, but when i click on one of the thumbnails a dialog box pops up saying "you have chosen to open download.php". the odd thing is though this doesnt happen all the time, sometimes the image comes up in a seperate window like i want it to.

also when i refresh the page on which the thumbnails are on it also pops up with a dialog box saying "you have chosen to open download.php. i just cant figure out which bit of code is making it do this, i think its is something to do with the headers but i do not know what to do to change it.

any help on this issue i have again would be very helpful, thanks again!

David

peteyb383
03-05-2008, 09:25 PM
Are you sure you got rid of the Content-Disposition header?

Seems like it could be a problem.

davidmerson
03-06-2008, 12:05 AM
yeah i have got rid of the content-disposition header, this problem only happens in firefox and someone told me that the dialog box poping up was just an error with firefox, is this anything you have come accross??maybe this is the reason?? thanks

David



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum