PHP: 无法获取文件内容
PHP: Not able to get file contents
我想获取我的 install.sql 文件的内容,该文件位于一个目录之上,但是当我使用 file_get_contents("../install.sql") 它时 returns 错误。
我该如何解决?
我也尝试过使用 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
}
?>
代码缩短
完整代码可用 here
对于建议删除“@”以显示错误的人:
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
对我来说,它没有任何意义,这就是我没有包括它的原因,但我们开始吧,以防出现我不知道的事情。
我已经解决了这个问题。
我这里也简单介绍一下。
所以这个安装文件是从另一个文件调用的,
// 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 帮助我
我想获取我的 install.sql 文件的内容,该文件位于一个目录之上,但是当我使用 file_get_contents("../install.sql") 它时 returns 错误。
我该如何解决?
我也尝试过使用 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
}
?>
代码缩短
完整代码可用 here
对于建议删除“@”以显示错误的人:
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
对我来说,它没有任何意义,这就是我没有包括它的原因,但我们开始吧,以防出现我不知道的事情。
我已经解决了这个问题。 我这里也简单介绍一下。
所以这个安装文件是从另一个文件调用的,
// 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 帮助我