7

私が使用しているPHPファイルがinstall.phpサブドメイン/サブディレクトリ(基本的にはdomain.com/install.phpではない)にあるかどうかを確認したいと思います。

私の問題の解決策を見つけました

下記参照

4

6 に答える 6

2

;の最後にがないため、構文エラーが発生します$scriptname="install.php"

あなたの方法はうまくいくはずです。

ファイルがフォルダーまたはサブドメインではなくドメイン ルートにインストールされているかどうかを判断する別の方法は、次のようになります。

function subdomboolcheck()
{
    $root = $_SERVER['DOCUMENT_ROOT'];
    $filePath = dirname(__FILE__);

    if ($root == $filePath) {
        return false; // installed in the root
    } else {
        return true;  // installed in a subfolder or subdomain
    }
}
于 2012-08-05T03:59:22.597 に答える
0

特定のディレクトリをスキャンするには:

if(file_exists('/subdir/install.php')) {
    // it exists there
} elseif(file_exists('/subdir2/install.php')) {
    // it exists there
} else {
    // it's not in these directories
}

すべてのディレクトリをスキャンするには:

$files = glob('/*');

foreach($files as $file) {
 //check to see if the file is a folder/directory
    if(is_dir($file)) {
        if(file_exists($file . 'install.php')) {
            // it was found   
        } else {
            // it was not found
        }
    }
}
于 2012-08-05T00:30:18.413 に答える
0

$_SERVER['SCRIPT_NAME']使用する代わりに$_SERVER['REQUEST_URI']

PHP $_SERVER のドキュメントを参照してください

于 2012-08-05T00:33:35.110 に答える