我想获取位于一个目录上的install.sql文件的内容,但是当我使用file_get_contents("../install.sql")时,它返回false。
我怎么才能修好它?
我还尝试使用fopen和fread。
<?php
// Get the install SQL Files
if (@$install_sql = file_get_contents("../install.sql")){
// Prepare the statement to install
$install_stmt = $conn_test->prepare($install_sql);
// Execute the install
$install_stmt->execute();
} else {
// This is where the code ends up
}
?>代码缩短
可用的完整代码这里
对于建议删除“@”以显示错误的人:
Warning:
file_get_contents(../install.sql): failed to open stream: No such file or directory in
/Users/yigitkerem/Code/SkyfallenSecureForms/Configuration/install.php
on line
55对我来说,这是没有任何意义的,这就是为什么我没有包括它,但我们现在去,以防有什么东西,我不知道。
发布于 2020-12-19 12:42:21
我已经解决了这个问题。我现在也将在这里简要说明这一点。
所以这个安装文件是从另一个文件中调用的,
// Unless the installation was complete, the Database Config should exist, if not, run the install.
if((@include_once SSF_ABSPATH . "/Configuration/SecureFormDatabaseConfiguration.php") === false){
// Include the install file
include_once SSF_ABSPATH."/Configuration/install.php";
// Stop further execution
die();
}我使用的是相对于配置文件夹中的install.php文件的路径,但是我使用的路径应该是相对于它调用的文件。
因此,为了避免将来遇到相同的问题,我现在从根文件中定义一个绝对路径,就像WordPress一样,用作引用,现在我不需要考虑从哪里调用该文件了。
感谢“Luuk”tadman帮了我
https://stackoverflow.com/questions/65369200
复制相似问题