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

download a HTTP hyperlink

Status
Not open for further replies.

meltdown

Programmer
May 1, 2002
7
0
0
CA
I have a hyperlink to a .doc file. I need it to ask the user to download the file instead of opening up word in the browser. Is there anyway to control this?
 
Many users don't have WinZip and they don't feel like downloading it.

I think the best way is just to instruct the user to right click on it (or Ctrl+click on a Macintosh) and choose "Save Target As..."

Will
 
can you have a server scripting language in your system?

If so you can create a script to do the download to the client.

If you can have PHP, it's only 3 or 4 lines of code.



Anikin
Hugo Alexandre Dias
Web-Programmer
anikin@anikin-skywalker.com
 
As simply as this:

$file=$_POST[path]."/".$_POST[document];
header("Content-type: ".ext2mime($_POST[document]));
header("Content-Disposition: attachment; filename=".$_POST[document]);
readfile($file);

You can save this file in the web root dir and name it download.php (for example)

Then instead of putting the real address of the document, you can put this (if you have all your documents inside the download dir:

<a href=&quot;/download.php?path=download&document=mydoc.doc&quot;>

Remember: PHP is a server side language. Your server must have php installed to use this.

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin@anikin-skywalker.com
 
no.. what was the error?


Anikin
Hugo Alexandre Dias
Web-Programmer
anikin@anikin-skywalker.com
 
MYDOC.HTM
<html>
<a href=&quot;/download.php?path=download&document=mydoc.doc&quot;>download</a>
</html>

DOWNLOAD.PHP
<?php
$file=$_GET[path].&quot;/&quot;.$_GET[document];
header(&quot;Content-type: &quot;.ext2mime($_GET[document]));
header(&quot;Content-Disposition: attachment; filename=&quot;.$_GET[document]);
readfile($file);
?>

Put those both in the root and put mydoc.doc in a folder named &quot;download&quot;.

Clive
 
apatterno: Many users don't have WinZip and they don't feel like downloading it.

That they have Word installed already suggests they're perfectly willing to load all sorts of crazy apps on their computer. [smile] You can always include a link to a downloadable install of WinZip!

You don't have to make it a zip file -- just some extension the browser doesn't recognize. &quot;.wordfile&quot; might do the trick.

I think the best way is just to instruct the user to right click on it (or Ctrl+click on a Macintosh) and choose &quot;Save Target As...&quot;

This is the simplest solution. Why won't this work for you?

CliveC: Why not save your doc file in html format.

This is the most graceful solution. Render it a non-problem.

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Just a note, saving something in HTML from Word is hideous, have a look at the source if you don't believe me, the file ends up about 20-50x bigger than it needs to be.
 
KempCGDR: Just a note, saving something in HTML from Word is hideous...

Oh, whoops. You're absolutely right, of course.

I was thinking &quot;develop and keep the document as an HTML document instead of a Word document&quot;, but I typed something else.

The idea being that if you intend to display it on the web, then have it start out as a web document.

But gotta keep coders busy, I guess... [smile]

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top