0

構成ファイルからのパスを、他のスクリプトの 1 つのディレクトリに、いくつかのディレクトリを上下に含める必要があります。

私の設定ファイルには次のような機能があります:

$execute_path = getcwd() . "/execute.php";

execute.php ファイルは、構成ファイルと同じディレクトリにあり、これにより問題がなくなり、出力は次のようになります。

public-html/config-directory/execute.php

元のディレクトリの外にあるディレクトリで同じ関数を使用すると、 getcwd() 関数がそのディレクトリにあるかのように扱われます。

たとえば、次のようにディレクトリ public-html/one/two/three/somefile.php から呼び出す場合:

<?php 
include(pathto/config.php)
echo $execute_path;
?>

出力は、publichtml/config-directory/execute.php のままではなく、publichtml/one/two/three/execute.php になります。

ここで私が望むものをどのように達成できますか? 長い説明で申し訳ありません。ありがとう。

4

1 に答える 1

1

インクルードは非常にトリッキーな場合があります。なぜ私はアドバイスが

//config.php

define("SITE_PATH", "public-html/config-directory");


//execute.php

$execute_path =SITE_PATH . "/execute.php";

//run.php
include_once 'config.php';
include_once 'execute.php';

echo $execute_path;
于 2012-04-27T16:54:18.507 に答える