に関するphpドキュメントで述べられているようにfile_exists()
:
Checks whether a file or directory exists
あなたの質問#3に対する私の唯一の推測は、ファイルが存在するかどうかを確認し、存在することです。ただ、それはファイルではなく、ディレクトリです。
#2に関しては、エラーメッセージにも記載されているように、次のようなことができます:
$file_to_check = ROOT . '/intl/codes/' . $シークレット;
if (file_exists($file_to_check)) {
if( !is_dir( $file_to_check ) )
unlink($file_to_check);
else
rmdir( $file_to_check );
$trusted = 'yes';
}
そして、あなたの一番の質問については、次のようなことをするかもしれません:
$secret = input_get($_GET['secret']);
if(isset($_POST['register']) && !empty($secret)) {
$file_to_check = ROOT . '/intl/codes/' . $secret;
if (file_exists($file_to_check)) {
if( !is_dir( $file_to_check ) )
unlink($file_to_check);
else
rmdir( $file_to_check );
$trusted = 'yes';
} else {
$trusted = 'no';
}
}
function input_get($key, $default = ""){
if(!isset($_GET[$key])){
return $default;
} else {
//do input cleanup first, if you want
return $_GET[$key];
}
}
少し説明:
- 何をするかわからないので、 called
check_input()
のラッパー関数を作成しました。これにより、実行する必要がなくなり、デフォルト値も入力されます。$_GET[]
input_get()
isset()
- 何度も入力する必要がないように、
ROOT . '/intl/codes/' . $secret;
変数に入れました。$file_to_check