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