0

So I have this sort of file set up. /cloud/ and /embed/ being two different subdomains.

www
  -cloud
   --config.php
   --files
     ---formSubmit.php
  -embed
    --index.php

in /embed/index.php I have the following code:

include("/www/cloud/files/formSubmit.php");

in /cloud/files/formSubmit.php I have the following code:

include("../config.php");

If I am on cloud.website.com and I go to the formSubmit.php, everything works fine and the config file is included.

However, If I am on embed.website.com and I go to the index.php, I get an error saying that config.php was not found.

Does anyone know what do I need to do to include my formSubmit.php from either location and have my config.php included?

bryan
  • 8,879
  • 18
  • 83
  • 166

1 Answers1

1

In this case, it seems your usage of relative paths is working and absolute paths are not. Whether that means the absolute path of /www/cloud/files/ is incorrect or not, I do not know. In my code, I tend to try to reference files relatively as much as possible like so:

// In embed/index.php
include_once dirname(dirname(__FILE__)) . '/cloud/files/formSubmit.php';

What that does is get the directory of the currently executing file and then it's parent directory, which would be www, and then goes back down the path from there to the file I need.

Subdomains should not make a difference when accessing files server side (as long as the files are hosted on the same server).

Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
  • Thank you, I think I understand what you are saying. so `../` works differently than `dirname()` because one is the absolute and one is the working path? – bryan Sep 02 '14 at 01:14
  • 1
    No. The `../config.php` is accessed as a **relative** path. The `/www/cloud/files/formSubmit.php` is being accessed as an **absolute** path. You mentioned the first is working and the second is not. That absolute path is probably incorrect, as it is typically `/var/www/...`, but regardless, you can access the file with a relative path instead as I indicated above. – Jeremy Harris Sep 02 '14 at 01:18
  • works for me, thanks for taking the time to explain. – bryan Sep 02 '14 at 01:19