file_put_contents() 期望参数 1 是有效路径,给定的字符串
file_put_contents() expects parameter 1 to be a valid path, string given
我有以下简单脚本(精简):
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
编辑 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
),它出错了......但是两个字符串是相同的
好吧,经过一番折腾,我找到了解决办法,given by @naviciroel
I got the same error before but I don't know if this solution of mine works on your problem you need to remove the "[=10=]" try replace it:
$cleaned = strval(str_replace("[=10=]", "", $buttons_first));
我有以下简单脚本(精简):
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
编辑 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
),它出错了......但是两个字符串是相同的
好吧,经过一番折腾,我找到了解决办法,given by @naviciroel
I got the same error before but I don't know if this solution of mine works on your problem you need to remove the "[=10=]" try replace it:
$cleaned = strval(str_replace("[=10=]", "", $buttons_first));