delphirules
delphirules

Reputation: 7408

Mirror downloads with PHP

Let's say i have a main site with a file to download, like :

www.mysite.com/download.zip

I have another domain :

www.myothersite.com

I want when the person goes to www.myothersite.com/download.zip , it serves the same file that is on www.mysite.com/download.zip .

But i don't want to copy the same file to myothersite, i want to have only one source of download, but in different domains. Is that possible with PHP ?

I know i can achieve this by editing the htaccess file. But is there a way to achieve the same results only using PHP ?

Thanks

Upvotes: 0

Views: 476

Answers (2)

Chin Leung
Chin Leung

Reputation: 14921

Why are you not linking it to the file directly?
For example, on your second website, you can put the link in the a tag directly to the file on your first website. You can also add the download attribute to your a tag to tell the browser it's a download.

HTML

<a href="http://site1.com/download.zip" download>Download</a>

For more information about the download attribute: http://www.w3schools.com/tags/att_a_download.asp

Upvotes: 1

NYG
NYG

Reputation: 1817

You can't with just php... In php you can do something like this:

in www.mysite.com you have a download.php file:

<?php

 if (isset($_GET['link'])) {
  header('Location: www.myothersite.com/'. $_GET['link'].'.zip');
  exit;
 }

?>

So www.mysite.com/download.php?link=download will lead to www.myothersite.com/download.zip.

This is just an example I don't know which and how many files you want to make available from your website.

Another way is to use an .htaccess config file.

Upvotes: 1

Related Questions