Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

force file to "download"

Status
Not open for further replies.

y2k1981

Programmer
Aug 2, 2002
773
IE
I don't know if this is possible, but hopefuly. i want to upload my CV (resume) to a http server (I don't have any admin rights to this server, it's just some webspace that I got with my POP3 account) so that it can be downloaded. I want to use .txt and .doc file formats. However, if a user using IE were to download the .doc file, IE would try to display it rather than prompt it to be downloaded. And as far as I know, nearly any browser will try to display a .txt file. So how can I "force" the browser to download them rather than displaying them, other than changing the extension?

 
Doesn't it depend on how the server is set up to handle mime types? It might not necessarily open in the browser window.

You could always do the old "Right click on the link and select save as" message.

MrBelfry

One of these days one of my posts might be helpful!
 
I'd suggest putting the Word document in a .zip file. Not only will it prevent the browser from opening the file, but also shorten the download time.
 
.doc and .txt files zip up really nicely and alwasy seem to produce a download prompt. Don't make self-extracting zip archives, though. People are leery of EXE files.

Wullie, can you write a few words about the content disposition header? I'm not familiar with that. Thanks!

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
Hi mate,

The Content-disposition header tells the browser what to do with the file. Using this you can tell the browser to download the file rather than show it inline.

The following is an example using Coldfusion.


If you want the code, just let me know. (I won't post it while the script is on my server)

Hope this helps

Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 
>Wullie
Can you specify some further information about ability to use this in php?? Just mail me some example of possible values of this header to gizmicek@seznam.cz, thanx
 
Hi mate,

I don't use PHP myself so I can't actually provide any accurate information about it.

If you do a google search for content-disposition php it shows quite a few results.

Hope this helps

Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 
My understanding for the disposition header you need:
Code:
content-disposition: attachment; filename=somefile.doc

Then some browsers might use the file extension to determine how to handle the file. Some browsers however might use the content-type header. If they do you can place some unknown type in there so they will choose to allow the user to save (download) the file
Code:
content-type: application/saveumust

The bottom line is that a browser will do what it wants and all you can do is set HTTP headers in an attempt to coerce it into the behavior you desire.


-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top