Page 1 of 1

retrieving images from mysql

Posted: Wed Mar 08, 2006 9:17 pm
by kirti
feyd | Please use

Code: Select all

and

Code: 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 help

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

and

Code: 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]

Posted: Wed Mar 08, 2006 9:24 pm
by feyd

Posted: Thu Mar 09, 2006 5:19 am
by kirti
hi thanks for replying. no mysql_fetch_row() doesn't give me anything. i don't understand why does the page stay blank? can you help me please cause i've spent days and days trying it out but nothing seems to be working.

thanks a lot

Posted: Thu Mar 09, 2006 5:22 am
by mickd
do a var_dump to see if you have actually extracted any information from the database.

Posted: Thu Mar 09, 2006 6:45 am
by kirti
basically i've one page which shows the list of images in the database. it shows two images that are stored in it. so i think they are stored in the database. sorry i.m very new to php. what do u mean by var_dump? thanks so much for replying.