I am trying to figure out how to put a link on my website that allows a visitor to download a file, e.g https://www.website.com/file.zip but that actually resides at

I haven't tried anything yet because I can't for the life of me figure it out hypothetically, theoretically or practically.

Yes, I have used Google, obv.

  • What does your website run? Does it run apache? php? cgi? asp? – LPChip Oct 25 '18 at 9:13

There are many ways to do this, depending on what your server supports.

Given that you listed php and html as tags for your question, I will limit this answer to those, but I assume apache is running behind it, which could also be used.

Basically, what you want to do is create a script or page that redirects to the new url.

The easiest and most elegant option is to use php, so I will start with this one.

You create a new page, for example, called download.php and inside you forward to the url. I could write a whole selector script with security checks etc, but that's outside of the scope of this question and would be more suitable on Stack Overflow too.

    $file = $_GET['file'];

Note, writing a new header requires that there was no previous output by the script, otherwise any output will write a standard header to the page and the header command won't work.

You would now make hyperlinks like:

<a href="https://www.example.com/download.php?file=actual_file.zip">Download</a>

HTML would require a page for each file, and tags to redirect to the download. This would mean that the url would change, but files can be controlled through those pages.

Lastly, htaccess can be used to mask the download.php file.

Also, htaccess can do everything without a php script too, but again, not sure if you are using Apache.

  • Considering this a proxy, no matter how one twists it, would the file be downloaded to the server first? Or would it merely be tunneled to the user? – vaid Oct 25 '18 at 9:40
  • Its tunneled to the user. If you want the server to download this, you need a lot more code, because then you probably want to cache the download too, and that means downloading it to a local place, and then redirect the script to that location instead. Such question would definitely require php and would be suitable for stack overflow. – LPChip Oct 25 '18 at 9:51
  • I see. Then your suggestion is exactly what I'm looking for. I need tunneling. – vaid Oct 25 '18 at 22:21

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.