You should NEVER force a download on anyone. How do they know it isn't
carrying a virus.
What you should do is to send the headers that prompt a dialog box for Save
or Open (I'm sure you've seen this).
I'm not sure which headers you use for csv or txt files but I do this with
PDFs all the time.
<?php
$fpd = "E:\\Pdf\\" . $fp . ".pdf";
$len = filesize($fpd);
header("Content-Type: application/pdf");
header("Content-Disposition: inline; filename=$fpd");
header("Content-Title: $fpd");
header("Content-Length: $len");
readfile($fpd);
?>
I suspect that you just need to change pdf to text in the Content-Type line.
Using the above script will always save the file as (scriptname.pdf)
so I've been a bit creative and when my user is heading towards a document,
an appropriately named script containing the above script is created
on the fly and called to handle the download. It is then deleted when
they confirm downloading.
The rest of my site uses Lasso so there's no point showing how those parts
work.
HTH
George
> -----Original Message-----
> From: Matt Babineau [mailto:ma...@criticalcode.com]
> Sent: 19 February 2003 4:24 pm
> To: php-w...@lists.php.net
> Subject: [PHP-WIN] Force a user to download a text file from a link
>
>
> How can I force a download of a TXT file from a Link? Or an Excel CSV
> file? using PHP of course too. I am running PHP 4.3 on W2K. Are there
> any tutorials for this?
>
> Thx-
>
> Matt
>
header("Content-Type: application/octet-stream");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=$name");
header("Content-Transfer-Encoding: text");
or this
header( "Content-type: application/octet-stream" );
header( "Content-Disposition: attachment; filename=$skeleton_name.skl" );
header( "Content-Length: $filesize" );
echo $file_contents;
or this
$size=filesize("urfile");
header("Content-Type: application/octet-stream");
header("Content-Length: $size");
header("Content-Disposition: attachment; filename=urfile_name.mp3");
header("Content-Transfer-Encoding: binary");
$fh = fopen("urfile_name", "r");
fpassthru($fh);
they all work for me =) I know I should pick one and stay with it but I get
bored =)
Matt,
HTH
George
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
<a href ="filename.txt">click here</a>
which, so far as I can see, will load said text page into the user's browser
window as soon as they click on the link. If the user then wants to save it,
they can use the browser's Save As function.
Too easy?
Jill
-----Original Message-----
From: FARRINGTON, RYAN [mailto:ryan.fa...@cingular.com]
Sent: Thursday, February 20, 2003 2:22 PM
To: 'George Pitcher'; Matt Babineau; php-w...@lists.php.net
Subject: RE: [PHP-WIN] Force a user to download a text file from a link
you could also try this:
or this
or this
No-one with any sense would ever download a Microsoft Word document off the
internet by choice, unless they had a serious amount of trust in the web
site owner, were browsing over a secure connection using SSL, and said
document was digitally signed with a PHP signature or similar. And even
then, you'd want to make sure your virus checker was switched on. This is
because Microsoft Word documents, like executables, CAN CARRY VIRUSES
(called Word Macros).
...and if you should _ever_ discover how to force someone to download
something against their will, then that of course would be highly
unethical...
Maybe I'm just missing the point here. Is it really TEXT documents you're
interested in, or something else? If it's text documents only, then my
original suggestion still stands. If it's something more sinister then
perhaps we should consider changing the thread title.
Jill
-----Original Message-----
From: FARRINGTON, RYAN [mailto:ryan.fa...@cingular.com]
Sent: Friday, February 21, 2003 1:28 PM
To: php-w...@lists.php.net
Subject: RE: [PHP-WIN] Force a user to download a text file from a link
that requires some form of trust in the user... I experience too many stupid
people in what I do on a day to day basis and it is just easier if it forces
a download...
typical user experience: I were a user and there was a link to a word
document that i wanted to edit. If I clicked on the link [and I had word
installed =)] it would open the file in my browser window and allow me to
edit it... but there is not toolbar for saving.. where are all my formatting
tools... oh no I've gotta call the person that put the link out because I
can't figure out what to do... help me ... BLAH!!! I hate people like that
so I force the download and they edit it locally and use the same page to
re-upload it.. it is just easier =)
Too easy?
Jill
-----Original Message-----
From: FARRINGTON, RYAN [mailto:ryan.fa...@cingular.com]
Sent: Thursday, February 20, 2003 2:22 PM
To: 'George Pitcher'; Matt Babineau; php-w...@lists.php.net
Subject: RE: [PHP-WIN] Force a user to download a text file from a link