gpt4 book ai didi

php - file_get_contents 不适用于本地文件

转载 作者:可可西里 更新时间:2023-10-31 22:07:43 24 4
gpt4 key购买 nike

我最近将我的 XAMPP 从 PHP 5.2 升级到 5.3.1

我似乎遇到了 file_get_contents() 的问题。

我可以使用该函数来获取类似“http://www.google.com”的内容,但是当我在本地设置的域上使用它时它会超时,例如“http://localhost/my_dir/my_css_file.css”。

我不太确定问题出在哪里。如果这是一个错误,是否有可行的替代方案?

请指教。

最佳答案

尝试使用 include() 而不是 file_get_contents()

<?php include($_SERVER['HTTP_HOST'] . "/my_dir/my_css_file.css"); ?>

<?php include($_SERVER['DOCUMENT_ROOT'] . "/my_dir/my_css_file.css"); ?>

根据您的评论更新:

$string = get_include_contents('somefile.php');

function get_include_contents($filename) {
if (is_file($filename)) {
ob_start();
include $filename;
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
return false;
}

这会将文件数据放入变量 $string

关于php - file_get_contents 不适用于本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3457692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com