共计 877 个字符,预计需要花费 3 分钟才能阅读完成。
问题描述
在使用WordPress时遇到以下TimThumb错误:
A TimThumb error has occured
The following error(s) occured:
* You may not fetch images from that site. To enable this site in timthumb, you can either add it to $ALLOWED_SITES and set ALLOW_EXTERNAL=true. Or you can set ALLOW_ALL_EXTERNAL_SITES=true, depending on your security needs.
错误查询字符串示例:
Query String : w=280&h=160&a=c&zc=1&q=90&src=http://wordpress.study-k8s.com/wp-content/uploads/2025/01/windows%E6%9C%8D%E5%8A%A1.png
TimThumb version : 2.8.14
原因分析
这个错误出现的原因是TimThumb默认的安全设置限制了外部图片的访问。需要在配置文件中开启外部图片访问权限。
解决方案
方案一:允许所有外部站点(简单但不够安全)
修改TimThumb配置文件(timthumb.php):
// ... existing code ...
define('ALLOW_EXTERNAL', true);
define('ALLOW_ALL_EXTERNAL_SITES', true);
// ... existing code ...
方案二:只允许特定域名(推荐)
修改TimThumb配置文件(timthumb.php):
// ... existing code ...
define('ALLOW_EXTERNAL', true);
$ALLOWED_SITES = array(
'wordpress.study-k8s.com',
'study-k8s.com'
);
define('ALLOW_ALL_EXTERNAL_SITES', false);
// ... existing code ...
正文完