retrieving images from mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kirti
Forum Newbie
Posts: 6
Joined: Sun Feb 19, 2006 4:46 am

retrieving images from mysql

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

kirti
Forum Newbie
Posts: 6
Joined: Sun Feb 19, 2006 4:46 am

Post 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
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

do a var_dump to see if you have actually extracted any information from the database.
kirti
Forum Newbie
Posts: 6
Joined: Sun Feb 19, 2006 4:46 am

Post 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.
Post Reply