Reputation: 13267
I'm new to PHP, so this is a very simple question. Let's say I have two folders: FolderA and FolderB. Within FolderA, I have a PHP file. Within FolderB, I have a certificate. If I wanted to insert the relative path to the certificate in the PHP file, would this be this path: ../FolderB/Certificate.pem
?
Thanks for your help!
Upvotes: 1
Views: 110
Reputation: 165069
Your solution entirely depends on whether or not the file in FolderA
is at the top of the "include tree".
A better solution would be to use an absolute path, eg
// FolderA/file.php
// PHP 5.3 only
$path = realpath(__DIR__ . '/../FolderB/Certificate.pem');
// or if stuck with PHP 5.2 or earlier
$path = dirname(dirname(__FILE__)) . '/FolderB/Certificate.pem';
To illustrate why an absolute path is better, consider this
// FolderA/file.php
$path = '../FolderB/Certificate.pem';
// some-other-file-in-the-root-directory.php
include 'FolderA/file.php';
// $path is now incorrect as it points to
// ROOT . '../FolderB/Certificate.pem'
Upvotes: 3
Reputation: 705
Unless you involved yourself in set_include_path() then yes you would be correct!
Upvotes: 0
Reputation: 30951
True.
/* FolderA/test.php: */
var_dump(is_file('../FolderB/Certificate.pem'));
Upvotes: 0