0

Is it possible to link files in two different add-on domains' folders together?

  • public_html/a //wordpress installation - domain appointed
  • public_html/b //custom cms installation - domain appointed

I have a file stored in folder b which I want to access through the page in folder a. possible? I have been able to locate the file and the name has started to appear, but on downloading, it gives me 404. The file name is there, the file is there but on download, 404. Already checked file permissions and they are good.

<?php

    $dir = "../b/files/"; //linking from a page in folder "a"

    if (!file_exists($dir)) {
        mkdir($dir, 0755);
        } else {

    // Open a directory, and read its contents
        $files = scandir($dir, 0);
        $count=1;
        for($i = 2; $i < count($files); $i++)
        echo  $count++ .".<a href='".$dir.$files[$i]."'>". $files[$i] ."</a><br>";

    }?>
stack kid
  • 117
  • 2
  • 12
  • Are you trying to download through browser? If you are able to access file then better write somewhere in folder a and make it to be downloaded. – Chetan Patel Apr 25 '17 at 10:01
  • Thank you Chetan! Yes, like I said, I can see the file appearing in folder a which resides in folder b. but on downloading, it doesn't work – stack kid Apr 25 '17 at 10:05
  • 1
    No, it wont work that way. You cant access other addon's file from http. You can do one thing.. just make download.php and pass file path as parameter and in download.php...get content of file which is hosted in other addon and write it in temp file in your current addon and make it downloaded. – Chetan Patel Apr 25 '17 at 11:01

1 Answers1

0

It is as simple as:

<a href="../b/myfile_to_download_here">Download</a>

Take a look at https://www.w3schools.com/html/html_filepaths.asp, it will give you an insight to paths and relative paths

Marin N.
  • 366
  • 3
  • 12
  • I have already done that. file is there, can see the name but on download, it doesn't work. I have already used the relative linking which made the file name appearing. They are two different add-on folders under public_html, and they have different domain names appointed. folder a has WordPress installation, and folder b has custom CMS. On localhost, it is working absolutely fine. – stack kid Apr 25 '17 at 10:07
  • Can you edit your question and share some of your code? – Marin N. Apr 25 '17 at 10:08
  • Thanks Marin. Please find the code above. Followed exactly what you have said in the previous answer. The issue is not linking but the downloading. I am almost there but there is something tiny I am missing. – stack kid Apr 25 '17 at 10:21
  • 1
    Your php code, before displaying some results at client level (in browser) it runs at server level. So, it finds the files, construct the links and then displays them. The problem appears at client level, when generating the page will generate a session/cookie for that subdomain. The links now instead seeing the root directory as being `public_html/a` will see it as `a.domain.com` therefore the relative path will refer to this new root when clicking the link. The fastest solution would be to use absolute paths at this point, and construct your download links like `b.domain.com/file` .. – Marin N. Apr 25 '17 at 10:38
  • that is exactly what I am getting if I use relative paths. `http://xyz.co(domain of folder a)/abc(folder b)/files/test.docx` still not working :( – stack kid Apr 25 '17 at 11:24
  • or absolute path. – stack kid Apr 25 '17 at 11:29
  • Isn't because after assigning the domains to folders, they have now become root themselves and can't be linked to their siblings until the folder i am trying to link should have in that add-on root domain folder? just get a thought. I don't know – stack kid Apr 25 '17 at 11:34
  • 1
    Well, that's what I was trying to explain with my previous comment :) – Marin N. Apr 26 '17 at 12:14
  • Thanks, Marin! get it done by placing the cms folders at directory 3rd level l.... so now main root has another folder with another website then another folder with another website then the cms folders. – stack kid Apr 26 '17 at 14:50
  • 1
    @stack kid Glad I could help. – Marin N. Apr 27 '17 at 16:03