|
-
Feb 26th, 2004, 12:15 PM
#1
Thread Starter
Ex-Super Mod'rater
Sending a file [Resolved]
How can I send a file using php, for example say how images get sent by something like:
PHP Code:
header("Content-type: image/png");
.....
Is there a way to send a header telling the browser its about to recieve a file for downloading.
Thanx
Last edited by Electroman; Feb 27th, 2004 at 06:44 AM.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Feb 26th, 2004, 12:20 PM
#2
Stuck in the 80s
I just tried this:
Code:
header('Content-type: image/gif');
header('Content-Disposition: attachment; filename="image.gif"');
readfile('image.gif');
And it popped up the download dialog. Is that what you want?
-
Feb 26th, 2004, 12:34 PM
#3
Thread Starter
Ex-Super Mod'rater
Kind of but I'm more after being able to get it to download Zip files.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Feb 26th, 2004, 12:38 PM
#4
Stuck in the 80s
For a zip file, just do:
And it will prompt to download the zip file.
-
Feb 26th, 2004, 12:42 PM
#5
Thread Starter
Ex-Super Mod'rater
Thanx, I'll give it a go.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Feb 26th, 2004, 01:21 PM
#6
Thread Starter
Ex-Super Mod'rater
Humm, this was strange, I just made that change and when I requested a file it displayed the file in text as garbage. However just as I was about to post a reply I tired it one last time and it worked. I hadn't even edited the file . Any how it works now so thank you very much.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Feb 26th, 2004, 05:34 PM
#7
Frenzied Member
if you are going to send a file in the header then you should be using these as well,
header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-type: application/x-zip");
header("Content-disposition: inline; filename=zip.zip);
header('Location: http://www.site.com/location/of/zip.zip');
-
Feb 26th, 2004, 11:12 PM
#8
Stuck in the 80s
-
Feb 26th, 2004, 11:24 PM
#9
Frenzied Member
because then this doesn't happen. you have to get the browser prepared to send it like that. it isn't like a link.
Originally posted by Electroman
Humm, this was strange, I just made that change and when I requested a file it displayed the file in text as garbage.
-
Feb 27th, 2004, 12:58 AM
#10
Stuck in the 80s
I've never had any problem just doing header('Location: url'); before. If you could point me into the direction of some documentation, that'd be great.
-
Feb 27th, 2004, 09:11 AM
#11
Frenzied Member
I am surprised you haven't as there are way to many bugs in IE and other browsers to get it right.
http://us2.php.net/manual/en/function.header.php
read through the comments and you will see some of the bugs and why those headers are important.
sending the zip file in the header and having php render the page as text/html and not the application/zip is what causes most of the problems.
the "Expires and Last-Modified" may not be as important but I just had them in my notes so I posted them as well.
-
Feb 27th, 2004, 10:22 AM
#12
Thread Starter
Ex-Super Mod'rater
Reading that page would it not be better using:
readfile('http://www.site.com/location/of/zip.zip')
instead of:
header('Location: http://www.site.com/location/of/zip.zip')
It mentions problem with old browsers tho, any idea what happens when these problems strike?
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Feb 27th, 2004, 10:59 PM
#13
Frenzied Member
you can use readfile if you are doing it that way. and what happens? well you experienced it yourslef, it loads the text in the browser. but that is only 1 of many bugs. I can't remeber them all.
-
Feb 28th, 2004, 02:11 PM
#14
For general binary data, use a application/octet-stream MIME type (Cotent-type). For others, you should look up the MIME type. Don't know where to best look for it though.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 2nd, 2004, 12:40 PM
#15
Stuck in the 80s
That's all jabberwocky to me.
-
Mar 2nd, 2004, 04:16 PM
#16
Then you'd best read up on the HTTP protocol...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 2nd, 2004, 04:30 PM
#17
Stuck in the 80s
Originally posted by CornedBee
Then you'd best read up on the HTTP protocol...
No. I refuse to learn.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|