Reply to Re: [PHP] Re: Hidden File Downloads

Your name:

Reply:


Posted by Richard Lynch on 10/26/22 11:14

On Mon, April 25, 2005 11:47 am, Philip Hallstrom said:
>>> Does anybody know how to do this with php? I'm not sure how to find
>>> the
>>> file in the backend and kick it back to the user with the "Save As" box
>>> popping up. I'm thinking maybe it has something to do with headers,
>>> but
>>> I'm not sure. Thanks.
>>>
>>> Stuart
>>
>> Usually when you send the header "application/octet-stream" this will
>> cause the "Save as" box.
>
> This is what I do to "force" excel docs to be downloaded...
>
> Header("Content-Type: application/vnd.ms-excel");

This tells the browser that it's an Excel file.

> Header("Content-Disposition: attachment; filename=general-data.xls");

This tells Microsoft browsers (who I think made up all the stuff in this
line on their own, disregarding existing standards) to handle this file as
an "attachment" and to name it "general-data.xls"

Now, I really don't know why their BROWSERS want to use the word
"attachment" (usually used in email) nor what that's supposed to mean,
but...

This will most likely *FAIL* for older non Microsoft browsers,
particularly if the user has some kind of plug-in that allegedly can
"handle" MS Excel files.

If you want to *FORCE* a download, the mime type
"application/octet-stream" *WILL* do that in an HTTP-compliant browser
(all of them).

> I found that just using the content type itself wasn't enough...

*WHICH* content type?

application/vnd.ms-excel ; This is a Microsoft Excel file. Handle it with
whatever plugin is configured to handle it, or prompt the user what to do.

application/octet-stream ; This should be downloaded. Period.

If you test on *ENOUGH* browser, focusing on older non-Microsoft browsers,
especially ones with a TON of plugins, you'll sooner or later find one
that won't do what you want with "application/vnd.ms-excel"

You won't find any that don't download "application/octet-stream" though.

You can still keep the attachment stuff, so most browsers will *NAME* the
file what you want.

You're better off, though, to force the URL to end in the filename you
want the user to use, as some browsers will not pay attention to the
"attachment" header.

YMMV

--
Like Music?
http://l-i-e.com/artists.htm

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация