Download link instead of open

T

Tom Gao

is there a way to force a download say if I point a url to a html file or a
pdf file instead of opening it just force it to download it ?

Thanks
Tom
 
W

WindAndWaves

Tom Gao said:
is there a way to force a download say if I point a url to a html file or a
pdf file instead of opening it just force it to download it ?

Thanks
Tom

Documents are always downloaded - except streaming objects - what do you
want to achieve?
 
T

Tom Gao

I want to click on a link on the page and have a box popup which say do you
want to save as...
and save the HTML file instead of opening it in the browser

Tom
 
B

Beauregard T. Shagnasty

Tom Gao wrote:

[top-posting corrected]
I want to click on a link on the page and have a box popup which
say do you want to save as... and save the HTML file instead of
opening it in the browser

Place a message on the page to advise your visitors to use:

1. File > Save As... choice on their browser's menu.
2. Right-click > Save As...

You cannot force anything.
 
D

Duende

While sitting in a puddle Beauregard T. Shagnasty scribbled in the mud:
You cannot force anything.

Yes you can.
I forced the lid off a jar of peanut butter today.
 
N

Neal

is there a way to force a download say if I point a url to a html file
or a
pdf file instead of opening it just force it to download it ?


Might be the first time this year this question has been asked! (Of
course, we neglect the 200 times last year...)

The answer is simply, no, no and, yes. No, I'm kidding. No.
 
T

Travis Newbury

Duende said:
While sitting in a puddle Beauregard T. Shagnasty scribbled in the mud:
Yes you can.
I forced the lid off a jar of peanut butter today.

Did you? Or did the peanuts finally just give in?
 
P

Peter - nativespace hosting

Tom said:
is there a way to force a download say if I point a url to a html
file or a pdf file instead of opening it just force it to download it
?

Thanks
Tom

You could zip the file up. The best thing to do is put a message near the
download link advising the user to right click, and 'save as'.
 
L

Leif K-Brooks

Neal said:
Might be the first time this year this question has been asked! (Of
course, we neglect the 200 times last year...)

Don't you mean 365*27 times last year?
 
B

Beauregard T. Shagnasty

Duende said:
While sitting in a puddle Beauregard T. Shagnasty scribbled in the
mud:


Yes you can. I forced the lid off a jar of peanut butter today.

Must have been a jar of Windows Peanut Butter. ;-)
 
Joined
Jul 18, 2012
Messages
1
Reaction score
0
WRONG WRONG WRONG!!!!

I really hate it when people come on forums and ask legitimate question and halfwitted programming hacks shoot them down and tell them its impossible....

There are 2 ways to do this, thats right not only is it NOT IMPOSSIBLE, there are 2 ways to do it!!!!

Option 1, place your DL's inside a specific folder and create an .htaccess file to tell the browser to serve these as downloads instead of content.
Code:
<FilesMatch "\.(html|jpg|png|gif)$">
 header set Content-Disposition attachment
</FilesMatch>

Option 2, use a PHP script to serve the file with a modified header:
PHP:
<?php
// Make sure only files in this directory are accessible by removing slashes
$file = str_replace('/','',$_GET['file']);
$file = str_replace('\\','',$file);
// If the file doesn't exist, show an error message and leave
if(!file_exists('downloads/' . $file) {
  header("HTTP/1.0 404 Not Found");
  echo 'The selected file doesn\'t exist';
  exit;
}
// Tell the browser to download the file
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment');
// Output the file data
echo file_get_contents('downloads/' . $file);
?>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top