I'm building a PHP CMS, but having trouble with variables. I want to be able to have all the variables in an external file, vars.php, and just include that file in every file that requires the variables. The variables all have to do with URLs and folder paths.
The problem I'm running in to is that if I set the variables to full URLs (ex: $uploadDir = "http://www.example.com/uploads/";
), the scripts don't do what they should. Same thing if I use absolute paths (ex: $uploadDir = "/uploads/";
or $uploadDir = "/full/server/path/uploads/";
).
If I use full URLs, it seems like it at least tries to work, but doesn't. If I use the full server path or absolute path, I get some error about that path not being allowed. The files are all stored in /edit/
or /edit/(sub-folder-name)/
, if that helps.
I'll look around for some code examples where I would be using this, and update this post ASAP.
Thanks.
UPDATE:
Some of the variables from this code snippet aren't included, just didn't think I should post a huge PHP script.
Example of $pageDir
:
// The below 2 lines are actually in vars.php, which is included in this file.
$pageDir = "http://www.example.com/edit/pages/";
$url = "http://www.example.com/";
if ($_POST["page"] && $execute == TRUE) {
$live = $_GET["p"] . ".php";
// The below line is how this used to be set up.
// $handle = fopen("pages/$page", "w");
// The below line is how the new version should be set up.
$handle = fopen("$pageDir/$page", "w");
fwrite($handle, $_POST["page"]);
fclose($handle);
// The below line is how this used to be set up.
// echo("<p>Page successfully saved. <a href=\"../$live\" target=\"_blank\">Click here to view this page.</a></p>
");
// The below line is how the new version should be set up.
echo("<p>Page successfully saved. <a href=\"$url/$live\" target=\"_blank\">Click here to view this page.</a></p>
");
$execute = FALSE;
}