php - 使用 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; ?>
解决方案
推荐阅读
- amazon-web-services - Lambda 缺少身份验证令牌
- r - 在字符串数组中查找最长的单个单词
- mysql - 一个查询加入多个表
- css - rails资产预编译给了我一个sass错误
- javascript - 无法在 React 应用程序的操作类中创建正确的 url
- javascript - 生成差异 JSON
- python - 完整的 Html 代码不导入 Beautiful Soup
- android - 为什么我的应用程序启动器图标在一个圆圈中?我可以用一个方形图标来代替这个吗?
- c++ - Qt5 远程对象 + 自定义类型但不在 POD 中
- r - 如何在不更改工作目录的情况下引用 R Studio 中的文件以进行本地 Shiny 应用程序开发