首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PHP:无法获取文件内容

PHP:无法获取文件内容
EN

Stack Overflow用户
提问于 2020-12-19 11:14:26
回答 1查看 94关注 0票数 0

我想获取位于一个目录上的install.sql文件的内容,但是当我使用file_get_contents("../install.sql")时,它返回false。

我怎么才能修好它?

我还尝试使用fopenfread

代码语言:javascript
复制
<?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
 }
?>

代码缩短

可用的完整代码这里

对于建议删除“@”以显示错误的人:

代码语言:javascript
复制
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

对我来说,这是没有任何意义的,这就是为什么我没有包括它,但我们现在去,以防有什么东西,我不知道。

EN

Stack Overflow用户

回答已采纳

发布于 2020-12-19 12:42:21

我已经解决了这个问题。我现在也将在这里简要说明这一点。

所以这个安装文件是从另一个文件中调用的,

代码语言:javascript
复制
// 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帮了我

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65369200

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档