You are here: Re: [PHP] Save page as text « PHP « IT news, forums, messages
Re: [PHP] Save page as text

Posted by "Richard Lynch" on 06/30/05 10:25

On Wed, June 29, 2005 2:22 pm, rm2004mail-listas@yahoo.com.br said:
> I have page with PHP and Javascript code and I need to a link or bottun in
> it to save its content to a plain text file. (I'm using an apache server
> in a machine running Windows 2003, and I want to be able to use this
> feature in IE 6 and Mozilla 1.7)
> I saw some information about how to do that with PHP, but I wasn't able to
> do it.
> Can some one help me with that?

<?php
header("Content-type: application/octet-stream");
?>

Any browser that does *NOT* do a download with that, is a badly-broken
browser indeed.

There are a bunch of Microsoft-only types who recommend some "other"
Content-type which just plain DOES NOT WORK on anything but IE. Surprised?
Don't be. That's how Microsoft encourages incompatible software to
retain market share.

There are other headers you can send that some browser will use to choose
the name of the file in the popup dialog where the user chooses to safe
the download. These headers DO NOT WORK in *all* browsers, only some.

If you want to be CERTAIN the download filename is what you want, then
make sure your URL "looks" like a static URL to the filename you want.

Specifically, convert a URL like:
http://example.com/download.php?filename=whatever.xyz

into:
http://example.com/download/whatever.xyz

You can do this by using .htaccess:
<Files download>
ForceType application/x-httpd-php
</Files>
to "force" Apache to treat "download" as a PHP script, even though it has
no .php in the filename.

Within your "download" script (nee download.php) you can use:
$_SERVER['PATHINFO'];
to access "/whatever.xyz" and use *THAT instead of $_GET['filename'] to
determine what file to download.

I posted an include file some time ago that makes it easy to translate
PATHINFO into an array $_PATH, which you treat pretty much like $_GET.

The only caveat is that $_GET is a SuperGlobal and I can't make $_PATH be
a SuperGlobal from within a PHP script. :-(

Search this group for my name and PATHINFO and that script ought to turn
up...


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

 

Navigation:

[Reply to this 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

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