Current location: Hot Scripts Forums » Programming Languages » PHP » Downloading Binary from mySQL


Downloading Binary from mySQL

Reply
  #1 (permalink)  
Old 10-22-05, 06:19 PM
dwoody dwoody is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Downloading Binary from mySQL

I have stored some binary data in a mySQL database and I am trying to create a page that will go through the database and create a page that has a series of links to download the original files. Right now the code below goes through the database and creates the link but when you click on the link rather than have the "Save file" dialog box appear is displays a page with a whole mess of data. How do I make it so that when the link is clicked the user can download it?

Quote:

<?
if(isset($_GET['id']))
{
include('configdb.php');
include('opendb.php');

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

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('configdb.php');
include('opendb.php');

$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=<?=$id;?>"><?=$name;?></a> <br>
<?
}
}
include('closedb.php');
?>
</body>
</html>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Useful MySQL Resources ptesone Database 30 02-23-11 08:28 AM
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
ASP upload prob minority ASP 1 06-27-05 08:35 AM
Binary Data From MySQL dwoody PHP 2 12-18-04 11:22 PM
Adding binary files to mysql? angst ASP 0 07-03-03 08:56 AM


All times are GMT -5. The time now is 06:17 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.