私が使用しているPHPファイルがinstall.php
サブドメイン/サブディレクトリ(基本的にはdomain.com/install.phpではない)にあるかどうかを確認したいと思います。
私の問題の解決策を見つけました
下記参照
私が使用しているPHPファイルがinstall.php
サブドメイン/サブディレクトリ(基本的にはdomain.com/install.phpではない)にあるかどうかを確認したいと思います。
下記参照
;
の最後にがないため、構文エラーが発生します$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
}
}
特定のディレクトリをスキャンするには:
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
}
}
}
$_SERVER['SCRIPT_NAME']
使用する代わりに$_SERVER['REQUEST_URI']
PHP $_SERVER のドキュメントを参照してください