retrieving image
Posted by: kirti (---.cable.ubr03.newm.blueyonder.co.uk)
Date: March 09, 2006 02:58AM

hi guys! basically i've been trying to upload and download images into and from the database. now i've managed to upload picture into the database but the problem is when i download it, it shows me an empty webpage. i've been trying to work it out but its not happening.

i took working code example from my friend and tried that which also gives me an empty webpage with no error, no image showing. though the same code provides my friend with an image retreived from the database. do i need to change any setting son my wampserver?? i'm using wamp5 1.5.0.

please help. i've a deadline and this is driving me insane.

the code i'm using to download is:

<?php
if(isset($_GET['id']))
{
// connect to mySql
$session = mysql_connect("localhost", "root", ""winking smiley;

// select the 'dreamhome' database
mysql_select_db("dreamhome"winking smiley;

$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"winking smiley;
header("Content-type: $type"winking smiley;

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", ""winking smiley;

// select the 'dreamhome' database
mysql_select_db("dreamhome"winking smiley;

$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="../../Documents%20and%20Settings/KIRTI%20RAM/Local%20Settings/Temporary%20Internet%20Files/Content.IE5/VZ7OZ8PS/download.php?id=<?=$id;?>"><?=$name;?></a> <br>
<?php
}
}


// close the connection
mysql_close($session);
?>
</body>
</html>

Options: ReplyQuote
Re: retrieving image
Posted by: CyberSpatium (---.hsd1.or.comcast.net)
Date: March 09, 2006 05:51AM

Why are you trying to access a php file in your IE temporary folder?
../../Documents%20and%20Settings/KIRTI%20RAM/Local%20Settings/Temporary%20Internet%20Files/Content.IE5/VZ7OZ8PS/download.php

This is not an actuall page accessable by your webserver. you need to put php files in your webroot (www folder), or they will not work.

Options: ReplyQuote
Re: retrieving image
Posted by: kirti (---.cable.ubr03.newm.blueyonder.co.uk)
Date: March 09, 2006 11:59AM

hi yeah i realised it and sorted it out but it still gives me a blank page. no error no image? what should i do?

Options: ReplyQuote
Re: retrieving image
Posted by: CyberSpatium (---.hsd1.or.comcast.net)
Date: March 09, 2006 06:58PM

add this to the top of your php script, and let me know what errors you get:

error_reporting(E_ALL);

this enables all error reporting. so, if there are any fatal errors in your code, they will show errors.

Options: ReplyQuote
Re: retrieving image
Posted by: kirti (---.cable.ubr03.newm.blueyonder.co.uk)
Date: March 10, 2006 12:00AM

i added it as you said to the top of the code and it didn't bring up any errors. do you think its a setting that needs to be changed somewhere.

<php>
error_reporting(E_ALL);

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


$session = mysql_connect("localhost","root",""winking smiley;
mysql_select_db("dreamhome"winking smiley;

$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_row($result);

header("Content-length: $size"winking smiley;
header("Content-type: $type"winking smiley;

echo $content;

mysql_close($session);
exit;
}
?>
<?php
$session = mysql_connect("localhost","root",""winking smiley;
mysql_select_db("dreamhome"winking smiley;

$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="try_new2.php?id=<?php=$id;?>"><?php=$name;?></a> <br>
<?php
}
}
mysql_close($session);
?>

</body>
</html>

Options: ReplyQuote


Sorry, only registered users may post in this forum.