首页 > 解决方案 > 使用 file_get_contents 和 get_bloginfo 时如何解决“无法打开流:连接超时...”?

问题描述

当我将 file_get_contents 与 get_bloginfo 一起使用时,当我在本地站点和登台服务器上工作时,它似乎工作正常。但是,当网站上线时它停止工作并给我这个错误“警告:file_get_contents(https://www.websiteurl.com/wp-content/themes/theme-name/assets/svg/logo.svg):未能打开流:第 38 行 /home/websiteurl/public_html/wp-content/themes/theme-name/header.php 中的连接超时。

当我打开此链接https://www.websiteurl.com/wp-content/themes/theme-name/assets/svg/logo.svg时,svg 加载得很好。那么为什么它会给我这个错误呢?

这是当前代码:

<?php
    $svgLogo = file_get_contents(get_bloginfo('template_url').'/assets/svg/logo.svg');
?>
<?php echo $svgLogo; ?>

当我将其更改为此错误消失:

<?php
    $svgLogo = file_get_contents('https://www.websiteurl.com/wp-content/themes/website-theme/assets/svg/logo.svg');
?>
<?php echo $svgLogo; ?>

标签: phpwordpress

解决方案


推荐阅读