retrieving images from mysql
Posted: Wed Mar 08, 2006 9:17 pm
feyd | Please use
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
hi guys. basically i've been trying to retrieve my images from the database and echo them on to a webpage. now i've successfully uploaded them but when i download them and ask php to echo it, its giving me a blank page. no error, no image nothing. do i need to change any setting in php.ini? the code that i'm using is given below. this is working example that my friend is using and it works for her but not for me. please please helpCode: Select all
<?php
if(isset($_GET['id']))
{
// connect to mySql
$session = mysql_connect("localhost", "root", "");
// select the 'dreamhome' database
mysql_select_db("dreamhome");
$id = $_GET['id'];
$query = "SELECT name, type, size, content FROM upload WHERE id = '$id'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
// header("Content-Disposition: attachment; filename=$name");
echo $content;
// close the connection
mysql_close($session);
exit;
}
?>
<html>
<head>
<title>Download File From MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
// connect to mySql
$session = mysql_connect("localhost", "root", "");
// select the 'dreamhome' database
mysql_select_db("dreamhome");
$query = "SELECT id, name 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) = mysql_fetch_array($result))
{
?>
a href="download.php?id=<?php=$id;?>"><?php=$name;?></a> <br>
<?php
}
}
// close the connection
mysql_close($session);
?>feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]