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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forced Download!! 1

Status
Not open for further replies.

vbkris

Programmer
Jan 20, 2003
5,994
IN
i have a php page that has a link to a text file, IE automatically opens the file without downloading it, what i want is that when the user clicks the link the download dialog box must appear whether IE can open the file or not....

Known is handfull, Unknown is worldfull
 
If you're sending data files of some sort which the user ought to be saving instead of viewing in his/her browser, the best MIME type to use is application/octet-stream; this will usually cause a "save" dialog box to appear.

found here

Kindest Regards
Jamie
 
thanks nightbite but how do i send the header (any e.g.), i am quite poor in delaing with headers..

Known is handfull, Unknown is worldfull
 
I think its something like this...

saveas.php should contain.

<?php header (&quot;Content-type: application/octet-stream&quot;); ?>
text to save


linking to savas.php should then do the trick
you can add anyhing to saveas.php but the header must be the fisrt thing to be output to the browser

hope that helps

Kindest Regards
Jamie
 
nope that didnt work

i have a viewarticle.php where the user can view any article and download any text file that comes with it.

in the viewarticle.php
<?php
header (&quot;Content-type: application/octet-stream&quot;);
include &quot;connection.php&quot;;
$id=$_POST['id'];
.....
?>

still it opens in the browser...

Known is handfull, Unknown is worldfull
 
try this


<?php
header (&quot;Cache-control: private&quot;);
header (&quot;Content-type: application/octet-stream&quot;);
include &quot;connection.php&quot;;
$id=$_POST['id'];
.....
?>


another example is


<?
header (&quot;Content-type: octet/stream&quot;);
header (&quot;Content-disposition: attachment; filename=&quot;.basename($file).&quot;;&quot;);
header(&quot;Content-Length: &quot;.filesize($file));
readfile($file);
exit;
?>


the php manual is quite detailed on headers.

Kindest Regards
Jamie
 
the first method does not work..
as to the second method there are problems:
1. i dont know how many files will be attached...

Known is handfull, Unknown is worldfull
 
Just put instructions above the link saying,

If you would like to save this as a file, Right click on the link, then select &quot;Save Target As...&quot;

That will open a dialog box asking the user if he or she would liek to save the text.

Thank you!!!

Mike Kovacic

&quot;&quot;&quot; &quot;&quot;&quot;
(o) (O)
\____/
 
The second one is what you need to do, you don't get to pass multiple files as part of a single web page. You could get clever with sessions and do it if it means that much to you, but you'll be loading a new page each time.

If you'd like advice to get clever with sessions let me know and I'll expound.

-Rob
 
sorry, but i fixed that problem...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top