次の簡単なスクリプトがあります(削除されています):
define("LANG_DIR", "../../app/lang/");
// define("LANG_DIR", "/var/www/html/app/lang/");
// #############
// Some parsing of an CSV file, from with we will create .php files
// #############
foreach ($fileContent as $fileName => $value) {
$fileString = FILE_START;
foreach ($value as $arrayKey => $arrayValue) {
$fileString .= TAB . "'" . $arrayKey . "'" . TAB . TAB . "=>" . TAB . TAB . "'" . $arrayValue . "'," . NL;
}
$fileString .= FILE_END;
$filePath = trim(LANG_DIR . $desLang . "/" . $fileName . ".php");
echo $filePath;
file_put_contents($filePath, $fileString);
}
そして、これらは私が受け取るエラーです:
../../app/lang/de/behandeling.php
Warning: file_put_contents() expects parameter 1 to be a valid path, string given in /var/www/html/public/scripts/languageImport.php on line 61
../../app/lang/de/bewaarplaats.php
Warning: file_put_contents() expects parameter 1 to be a valid path, string given in /var/www/html/public/scripts/languageImport.php on line 61
../../app/lang/de/cron.php
Warning: file_put_contents() expects parameter 1 to be a valid path, string given in /var/www/html/public/scripts/languageImport.php on line 61
../../app/lang/de/gebruikers.php
Warning: file_put_contents() expects parameter 1 to be a valid path, string given in /var/www/html/public/scripts/languageImport.php on line 61
../../app/lang/de/handelshuis.php
Warning: file_put_contents() expects parameter 1 to be a valid path, string given in /var/www/html/public/scripts/languageImport.php on line 61
../../app/lang/de/heftrucks.php
Warning: file_put_contents() expects parameter 1 to be a valid path, string given in /var/www/html/public/scripts/languageImport.php on line 61
../../app/lang/de/history.php
Warning: file_put_contents() expects parameter 1 to be a valid path, string given in /var/www/html/public/scripts/languageImport.php on line 61
他の (コメント付きの) 定義を使用すると、同じエラーが発生します。
問題は、同じフォルダーにある別のスクリプトで同じ定義を使用し、そこからファイルにアクセスできることです。したがって、パスは正しいですが、file_put_contents
見つけることができません。
@e-Learner の要求に応じて編集 します。使用したときに得られる出力は次のとおりです。
var_dump(is_file(LANG_DIR . $desLang . "/" . $fileName . ".php"));
// This will output:
Warning: is_file() expects parameter 1 to be a valid path, string given in /var/www/html/public/scripts/languageImport.php on line 63
NULL
Warning: is_file() expects parameter 1 to be a valid path, string given in /var/www/html/public/scripts/languageImport.php on line 63
NULL
Warning: is_file() expects parameter 1 to be a valid path, string given in /var/www/html/public/scripts/languageImport.php on line 63
NULL
Warning: is_file() expects parameter 1 to be a valid path, string given in /var/www/html/public/scripts/languageImport.php on line 63
NULL
Warning: is_file() expects parameter 1 to be a valid path, string given in /var/www/html/public/scripts/languageImport.php on line 63
NULL
Warning: is_file() expects parameter 1 to be a valid path, string given in /var/www/html/public/scripts/languageImport.php on line 63
NULL
edit 2いくつかのコードを変更しました:
$filePath = trim(LANG_DIR . $desLang . "/" . $fileName . ".php");
echo $filePath . "<br />";
var_dump(is_file("/var/www/html/app/lang/de/behandeling.php"));
var_dump(is_file($filePath));
これにより、次のようになります。
/var/www/html/app/lang/de/behandeling.php
/var/www/html/app/lang/de/behandeling.php
bool(true)
Warning: is_file() expects parameter 1 to be a valid path, string given in /var/www/html/public/scripts/languageImport.php on line 68
ご覧のとおり、文字列全体を使用すると、スクリプトはファイルにアクセスできます。しかし、その場で文字列を作成すると(を挿入して$fileName
)、うまくいきません...しかし、両方の文字列は同じです