473,566 Members | 2,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

download binary files from database

Dux
I have used some example code to create a database in MySQL and using
php I can add binary files to the database. I was under the impression
that I would be able to download the files with the source code
provided, but am having trouble doing that.

<?php
if ($id_files) {
include "./include/open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM tbl_Files
WHERE id_files=$id_fi les";

$result = @mysql_query($s ql, $db);
$data = @mysql_result($ result, 0, "bin_data") ;
$name = @mysql_result($ result, 0, "filename") ;
$size = @mysql_result($ result, 0, "filesize") ;
$type = @mysql_result($ result, 0, "filetype") ;

header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name" );
header("Content-Description: PHP Generated Data");
echo $data;
}
?>

I thought I would be greeted with a dialog box asking me where i want to
save my file.

Am I getting the wrong impression?

How would I go about downloading the data from database?

Thanks.

Jul 16 '05 #1
3 10828
Maybe the filetype is incorrect, I suggest to use application/octet-stream.
I could get it with this.

"Dux" <du*@nospam.com > wrote in message
news:be******** **@titan.btinte rnet.com...
I have used some example code to create a database in MySQL and using
php I can add binary files to the database. I was under the impression
that I would be able to download the files with the source code
provided, but am having trouble doing that.

<?php
if ($id_files) {
include "./include/open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM tbl_Files
WHERE id_files=$id_fi les";

$result = @mysql_query($s ql, $db);
$data = @mysql_result($ result, 0, "bin_data") ;
$name = @mysql_result($ result, 0, "filename") ;
$size = @mysql_result($ result, 0, "filesize") ;
$type = @mysql_result($ result, 0, "filetype") ;

header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name" );
header("Content-Description: PHP Generated Data");
echo $data;
}
?>

I thought I would be greeted with a dialog box asking me where i want to
save my file.

Am I getting the wrong impression?

How would I go about downloading the data from database?

Thanks.

Jul 16 '05 #2
"Sebestyén Dénes" wrote:
Maybe the filetype is incorrect, I suggest to use application/octet-stream.
I could get it with this.

"Dux" <du*@nospam.com > wrote in message
news:be******** **@titan.btinte rnet.com...
I have used some example code to create a database in MySQL and using
php I can add binary files to the database. I was under the impression
that I would be able to download the files with the source code
provided, but am having trouble doing that.

<?php
if ($id_files) {
include "./include/open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM tbl_Files
WHERE id_files=$id_fi les";

$result = @mysql_query($s ql, $db);
$data = @mysql_result($ result, 0, "bin_data") ;
$name = @mysql_result($ result, 0, "filename") ;
$size = @mysql_result($ result, 0, "filesize") ;
$type = @mysql_result($ result, 0, "filetype") ;

header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name" );
header("Content-Description: PHP Generated Data");
echo $data;
}
?>

I thought I would be greeted with a dialog box asking me where i want to
save my file.

Am I getting the wrong impression?

How would I go about downloading the data from database?

Thanks.


Thanks for help, but....

Still not getting a file to download. My database output looks like this:

Filename Type Size
Description

putty.exe application/octet-stream 356352 Putty
Application, ssh client for win32 (Download )
readme.txt text/plain 9851
mozilla readme ( Download )

So the type is application/octet-stream, but still no download.

What am I missing?

Jul 16 '05 #3
Is the case of the field-name OK? Because I think php is case-sensitive for
getting variables from a database, and I can't think anything else that can
cause an error like this...
Maybe for debugging try to change header() to echo to see if it's right.

"duxbuz" <we*******@duxb uz.com> wrote in message
news:3F******** *******@duxbuz. com...

Thanks for help, but....

Still not getting a file to download. My database output looks like this:

Filename Type Size
Description

putty.exe application/octet-stream 356352 Putty
Application, ssh client for win32 (Download )
readme.txt text/plain 9851
mozilla readme ( Download )
So the type is application/octet-stream, but still no download.

What am I missing?

Jul 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5819
by: peetm | last post by:
I'd like to write to a log whenever a visitor to my site downloads a file. So, I'd like the link they click to be to a php 'page' that returns the file. Don't know how to do that! Side Question ... Presumably, the dialog that you see when you download a binary (asking for a 'Save As...' file name) is put up by your browser when it...
5
6098
by: Brandon Walters | last post by:
I wrote a file download module for my website. The reason for the file download module is that my website downloads work on a credit based system. So I need to keep track of and limit daily downloads. It uses fpassthru() and some headers() to send a file to the requesting user. The get.php file that I wrote (the file download module if you...
1
2051
by: surfspider | last post by:
Hi, I have a little problem with the header function. I have a few links to pdf files on eshop.php. The links are like this : download.php?pdfid=1 In download.php I get the filename from the database and initiate the download. If I click on the link, I get the internet explorer dialog box "open, save or cancel". If I choose save, it...
12
5426
by: Swede | last post by:
Hello, I am posting this rather lengthy description here in hope of getting at least some insight into a problem that is really hurting my business, since I have come to the conclusion that my problem is at least partly PHP-related. Some time now I have been having transfer problems, i.e. my customers downloads of large binary (ZIP)...
0
3034
by: Chuck Anderson | last post by:
I am writing a Php script to run on my home PC (Windows) that downloads an Apache access log file and inserts new entries into a database.. The only way I can access these log files is through a cPanel URL that delivers a gzipped copy of the log file with all entires for the current month (up to the current date and time). I want to run...
17
2271
by: Kevin Goodsell | last post by:
Is there a place I can download the last public draft for C89? What about a draft for C95? What I really need is a list of all standard library functions, macros, types, etc. for a "keyword file", which is used for syntax highlighting. I want to create one for both major C standards, with the C89/90 version including the 1995 amendment. I...
5
1572
by: sc48567189 | last post by:
Hello ! I need some help here. I google after the response but with no sucess. I need to download - randon size - parts of a file, not the whole file. Says: I have the zip file test.zip, it is 10 mega bytes long. But I don't want the 10 mega today. Today I want 5 mega bytes. Tomorrow I could want more 3 mega bytes of the file, but it is not...
2
1672
by: =?Utf-8?B?SHVzYW0=?= | last post by:
Hi EveryBody: I'm working with project in my company by using ASP.Net 2.0 that allow the users to upload and download files to web site in the internet as backup. The user will first upload his or her own files in the website that will save the data immediatlly into database. and when the user sign in into his or her account he can...
1
47385
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or...
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.