473,513 Members | 2,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using header functions in php

hi,

i am trying to create code that will prompt the user to download.
below is the code i am using:
..
..
..

$content = datadump ("clients");

$file_name = "MySQL_Database_Backup.sql";
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=$file_name");
'datadunp' is simply a function that i have created to generate a sql
string from my databases and return the value into $content.

unfortunately, when i run this code from the server, it doesnt do
anything. i have noticed that i am gettin errors when i place the code
with the header function anywhere but the top of the document but even
without error, it isnt doin anything.

btw, i got this code from a web page
(http://www.devpapers.com/article/55) and modified it as i dont really
have a great knowledge of header functions in php. any help would be
great. cheers

burnsy
Jul 17 '05 #1
5 3286
mr_burns wrote:
i am trying to create code that will prompt the user to download.
[It looks like your [shift] key is broken. You should have that fixed.]

There's no way to force a download (or much of anything on the www).
Your best bet is to honestly declare the MIME type and let the browser
handle it from there.
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=$file_name"); i have noticed that i am gettin errors when i place the code with the
header function anywhere but the top of the document
You must send headers before any character data -- including whitespace
-- is sent.
but even without error, it isnt doin anything.


You're sending data after the headers, right? So this data is sent by
the server, but the browser does nothing with it?

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 17 '05 #2
bi******@yahoo.co.uk (mr_burns) wrote in message news:<65**************************@posting.google. com>...
hi,

i am trying to create code that will prompt the user to download.
below is the code i am using:
.
.
.

$content = datadump ("clients");

$file_name = "MySQL_Database_Backup.sql";
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=$file_name");
'datadunp' is simply a function that i have created to generate a sql
string from my databases and return the value into $content.

unfortunately, when i run this code from the server, it doesnt do
anything. i have noticed that i am gettin errors when i place the code
with the header function anywhere but the top of the document but even
without error, it isnt doin anything.

btw, i got this code from a web page
(http://www.devpapers.com/article/55) and modified it as i dont really
have a great knowledge of header functions in php. any help would be
great. cheers

burnsy


header("Content-type: application/text");

header("Content-Disposition: attachment; filename=".$file_name);

print $all_data;

important: you have to send the download header before anything else
to the browser. so if your datadump creates any output the download
header becomes invalid. if datadump shall create output before the
header is sent, use ob_start() to buffer and ob_flush() to release the
output after the header is sent.

micha
Jul 17 '05 #3
chotiwallah wrote:
bi******@yahoo.co.uk (mr_burns) wrote
i am trying to create code that will prompt the user to download.

[ ... ]
header("Content-type: application/text");


RFC2616 discourages the use of non-registered media types.

Below is an excerpt from Brian's article, in case it didn't
reach you.

| There's no way to force a download (or much of anything on
| the www). Your best bet is to honestly declare the MIME
| type and let the browser handle it from there.

news:10************@corp.supernews.com

[ ... ]

--
Jock
Jul 17 '05 #4
John Dunlop wrote:
chotiwallah wrote:
header("Content-type: application/text");

RFC2616 discourages the use of non-registered media types.


And if you are going to do something non-standard, at least use an "x-"
prefix.

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 17 '05 #5
bi******@yahoo.co.uk (mr_burns) wrote in message news:<65**************************@posting.google. com>...
<snip>
unfortunately, when i run this code from the server, it doesnt do
anything. i have noticed that i am gettin errors when i place the code
with the header function anywhere but the top of the document but even
without error, it isnt doin anything.


0. Define exactly _what_ did work and what didn't work?
1. Manual and usernotes are your friend: www.php.net/<keyword>
2. http://in2.php.net/header & http://in2.php.net/outcontrol
3. MSIE needs different headers to be sent to trigger download. Refer
usernotes at http://in2.php.net/header
4. If you call download url in single browser window, it won't work.
You have to enter the url from some other anchor tags by clicking.

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #6

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

Similar topics

5
1931
by: Tony Johansson | last post by:
Hello experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that sound strange. Here is the whole section: It says" Because...
5
562
by: Daniel Nichols | last post by:
I've noticed that in a C module (.c, .h file combination) that if you create a function's definition before it is used in other functions than a declaration is not necessary. I believe if the...
6
31465
by: Ravi | last post by:
Hi All: Is there any reason for declaring functions as static in a header file if that header file is going to be included in several other files? The compiler throws a warning for every such...
4
2022
by: Christoph Scholtes | last post by:
Hi, I have some questions about header files: Say I have a file functions.c which contains a couple of functions. I have declared some structs in this file too. The structs are defined in...
11
2559
by: ruffiano | last post by:
A colleague of mine who is a C developer wrote several functions in C which I now need to invoke in my C++ application. This is normally not a problem except that the header file that he wrote...
16
2064
by: wdh3rd | last post by:
Hi everyone. I'm new to C and I have a few questions: I am making files for permutations and combinations. Files to be made are perm.c, perm.h, combo.c, and combo.h. Since both combinations...
6
2137
by: greek_bill | last post by:
Hi, I'm interested in developing an application that needs to run on more than one operating system. Naturally, a lot of the code will be shared between the various OSs, with OS specific...
21
34328
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 Uploading files from a local computer to a remote web server has many useful purposes, the most...
221
366985
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
0
7260
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,...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
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...
0
5686
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,...
1
5089
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...
0
3234
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...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.