我在博客中使用 WordPress,但我在 error_log 中看到重复的错误,如下所示。我该如何解决这个问题?
谢谢。
错误日志
[29-Nov-2015 12:01:14 UTC] PHP Warning: getimagesize(http://hardal.com/wp-content/uploads/2015/11/glogo.png): failed to open stream: HTTP request failed! in /home/hardal/public_html/wp-content/themes/hardal/header.php on line 36
[29-Nov-2015 12:01:14 UTC] PHP Warning: getimagesize(http://hardal.com/wp-content/uploads/2015/11/glogo21.png): failed to open stream: HTTP request failed! in /home/hardal/public_html/wp-content/themes/hardal/functions/theme-actions.php on line 38
theme-actions.php 第 36 至 41 行
<div class="row" id="copyright-note">
<?php if ($albay_options['albay_footer_logo'] != '') { ?>
<?php list($width, $height, $type, $attr) = getimagesize($albay_options['albay_footer_logo']); ?>
<div class="foot-logo">
<a href="<?php echo home_url(); ?>" rel="nofollow"><img src="<?php echo $albay_options['albay_footer_logo']; ?>" alt="<?php bloginfo( 'name' ); ?>" <?php echo $attr; ?>></a>
</div>
header.php 第 33 至 43 行
<?php if ($albay_options['albay_logo'] != '') { ?>
<?php if( is_front_page() || is_home() || is_404() ) { ?>
<h1 id="logo" class="image-logo">
<?php list($width, $height, $type, $attr) = getimagesize($albay_options['albay_logo']); ?>
<a href="<?php echo home_url(); ?>"><img src="<?php echo $albay_options['albay_logo']; ?>" alt="<?php bloginfo( 'name' ); ?>" <?php echo $attr; ?>></a>
</h1><!-- END h1-->
<?php } else { ?>
<h2 id="logo" class="image-logo">
<?php list($width, $height, $type, $attr) = getimagesize($albay_options['albay_logo']); ?>
<a href="<?php echo home_url(); ?>"><img src="<?php echo $albay_options['albay_logo']; ?>" alt="<?php bloginfo( 'name' ); ?>" <?php echo $attr; ?>></a>
</h2><!-- END h2-->
最佳答案
How can I solve this problem?
嗯,看来您需要对其进行更多测试,以确定问题所在,然后再开始解决它。
error_log
为您提供了一些线索,让您知道 getimagesize
函数在处理 时出现了关于
和另一个 URL。HTTP 请求
的问题http://hardal.com/wp-content/uploads/2015/11/glogo.png
由于它链接到 HTTP 请求
,为了找出到底是什么错误,您可能需要 $http_response_header
变量。
http://php.net/manual/en/reserved.variables.httpresponseheader.php
The $http_response_header array is similar to the get_headers() function. When using the HTTP wrapper, $http_response_header will be populated with the HTTP response headers. $http_response_header will be created in the local scope.
请注意,仅当 HTTP 包装器
成功连接到 HTTP 服务器并且该服务器确实响应时,此变量才可用。如果它不是 HTTP 服务器或连接失败,则 $http_response_header
将为空或未设置。
因此,出于调试(或寻找原因)的目的,您可以编写如下代码:
getimagesize('http://hardal.com/wp-content/uploads/2015/11/glogo.png');
if (empty($http_response_header)) {
exit('Connection failed.');
}
// See if the response string contains `200`. works in `HTTP/1.1` at least
if (strpos($http_response_header[0], '200') === false) {
exit('HTTP Error: ' . $http_response_header[0]);
}
运行它,这将打印出更详细的错误信息。然后:
- 如果显示“连接失败”,请检查您的端口、防火墙相关内容。
- 如果显示“HTTP 错误:blablabla”,请检查您的目标 (hardal.com) HTTP 服务器的设置。
注意:请记住在返回生产之前删除上述用于调试的代码。
关于php - getimagesize() 无法打开流 : HTTP request failed! 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33995525/