今天在我的博客上工作时,WordPress在上传图片时 显示HTTP错误,我感到困惑和无助。我尝试一次又一次地上传图像,但错误不会消失。经过 5-6 次尝试后,我能够再次成功上传图像。但我的成功是短暂的,因为几分钟后同样的错误来敲我的门。
虽然上述问题有许多可用的修复程序,但它们会再次浪费您的时间,这就是为什么我要在上传图像时修复此HTTP错误,并且在您完成本文后,我可以向您保证此错误消息将是早就没了。
修复(Fix)WordPress在上传图像时显示HTTP错误(HTTP Error)
图片大小(Image Size)
首先要检查的显而易见的事情是您的图像尺寸不超过您的固定宽度内容区域。例如,假设您要发布 3000X1500 的图像,但发布内容区域(由您的主题设置)只有 1000 像素,那么您肯定会看到此错误。
注意:(Note:)另一方面,请始终尝试将图像尺寸限制为 2000X2000。
虽然上述可能不一定能解决您的问题,但再次值得检查。如果您想查看有关图像的WordPress指南,请在此处阅读(read here)。
增加你的 PHP 内存(Increase your PHP memory)
有时增加WordPress允许的PHP内存似乎可以纠正这个问题。好吧(Well),在您尝试之前,您永远无法确定,将此代码define('WP_MEMORY_LIMIT', '64M')添加到您的wp-config.php文件中。
注意:不要触摸 wp-config.php 中的任何其他设置,否则您的站点将完全无法访问。如果您愿意,可以阅读有关编辑 wp-config.php 文件的(Editing wp-config.php file)更多信息。
要添加上述代码,只需转到您的 cPanel 并转到WordPress安装的根目录,您将在其中找到 wp-config.php 文件。
如果上述方法对您不起作用,那么您的网络托管服务提供商很可能不允许您增加PHP内存限制。在这种情况下,直接与他们交谈可以帮助您更改PHP内存限制。
将代码添加到 .htaccess 文件(Adding a code to .htaccess file)
要编辑您的.htaccess文件,只需导航到Yoast SEO > Tools > File Editor(如果您没有安装 Yoast SEO,那么您应该安装它,您可以在此处阅读有关如何配置此插件的信息(how to configure this plugin here))。在 .htaccess 文件中只需添加这行代码:
SetEnv MAGICK_THREAD_LIMIT 1
添加代码后,只需单击“保存更改为 .htaccess”并检查问题是否已解决。
更改主题 functions.php 文件(Changing theme functions.php file)
实际上,我们只是要使用主题函数.php 文件告诉WordPress使用 GD 作为默认的WP_Image_Editor类。(WP_Image_Editor)从WordPress最新更新开始,GD 已经被抽象化, Imagick被用作默认图像编辑器,所以回到旧版本似乎可以为每个人解决问题。
推荐:(Recommended:)显然,还有一个插件可以做到这一点,去这里。(go here.) 但是,如果您想手动编辑文件,请在下面继续。
要编辑主题函数.php 文件,只需导航到Appearance > Editor并选择主题函数(Theme Functions)(function.php)。到达那里后,只需在文件末尾添加以下代码:
add_filter( ‘wp_image_editors’, ‘change_graphic_lib’ );
function change_graphic_lib($array) {
return array( ‘WP_Image_Editor_GD’, ‘WP_Image_Editor_Imagick’ );
}
注意:(Note:) 确保(Make)在结束PHP 符号 (?>)中添加此代码
这是指南中最重要的修复WordPress在上传图像时显示HTTP错误,但如果您的问题仍未解决,请继续前进。
禁用 Mod_Security(Disabling Mod_Security)
注意:(Note:)不建议使用此方法,因为它可能会危及您的WordPress和主机的安全性。仅当您尝试了其他所有方法并且禁用此方法对您有效时才使用此方法,然后联系您的托管服务提供商并寻求支持。
再次通过 Yoast SEO > Tools > File Editor进入您的文件编辑器,并将以下代码添加到您的 .htaccess 文件中:
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
然后单击“保存更改为 .htaccess”。
重新安装最新版本的 WordPress(Reinstalling the latest version of WordPress)
有时,由于WordPress(WordPress)文件损坏,可能会出现此问题,并且上述任何解决方案都可能根本不起作用,在这种情况下,您必须重新安装最新版本的WordPress:
- (Backup)从 cPanel备份您的插件文件夹((Plugin)下载(Download)它们),然后从WordPress禁用它们。之后,使用 cPanel 从您的服务器中删除所有插件文件夹。
- 安装标准主题,例如二十(Twenty)十六,然后删除所有其他主题。
- 从Dashboard > Updates重新安装最新版本的WordPress。
- 上传并激活所有插件(图像优化插件除外)。
- 安装您想要的任何主题。
- 现在尝试使用图像上传器。
这将修复WordPress在上传图像时显示HTTP错误。(HTTP)
杂项修复(Miscellaneous Fixes)
- 不要在图像文件名中使用撇号,例如 Aditya-Farrad.jpg
- 尝试更改文件的扩展名。
- 禁用所有插件。
- 确保(Make)您的主机安装了最新版本的PHP。
- 请联系您的托管服务提供商以获得支持。
本指南到此结束,我希望您现在已经解决了WordPress 在上传图片时显示 HTTP 错误(WordPress shows HTTP error when uploading images)的问题。如果您对这篇文章仍有任何疑问,请随时向他们提问。
喜欢并在社交网络中分享此博客文章,以帮助传播有关此问题的信息。(Like and share this blog post in the social networks to help spread the word about this problem.)
WordPress shows HTTP Error when uploading images
Whіle working on my blog today WordPress shows HTTP error when uploading images, I was confused and helpless. I tried tо upload the image again & again, but the error won’t go. After 5-6 attempts I was able to again υploаd the images successfully. But my sυссeѕs waѕ short lived as after a few minutes the same error comes knоckіng at my door.
While there are many fixes available for the above problem but then again they will waste your time, that’s why I am going to Fix this HTTP error when uploading images and after you are done with this article I can assure you that this error message will be long gone.
Fix for WordPress shows HTTP Error when uploading images
Image Size
This first and obvious thing to check for is that your image dimensions don’t exceed your fixed width content area. For example, let’s say you want to post 3000X1500 image but the post content area (set by your theme) is only 1000px then you will definitely see this error.
Note: On the other hand always try to limit your image dimensions to 2000X2000.
While the above may not necessarily fix your issue but again it’s worth checking. If you want to check WordPress guidelines on images please read here.
Increase your PHP memory
Sometimes increasing the PHP memory allowed to WordPress seems to rectify this issue. Well, you can never be sure until you try, add this code define(‘WP_MEMORY_LIMIT’, ’64M’) into your wp-config.php file.
Note: Don’t touch any other settings in wp-config.php or else your site will completely become inaccessible. If you want you can read more about Editing wp-config.php file.
To add the above code, just head over to your cPanel and go to the root directory of your WordPress installation where you will find the wp-config.php file.
If the above doesn’t work for you then there is a good chance that your web hosting provider doesn’t allow you to increase PHP memory limit. In that case talking directly to them can help you in changing the PHP memory limit.
Adding a code to .htaccess file
To edit your .htaccess file just navigate to Yoast SEO > Tools > File Editor (if you don’t have Yoast SEO installed, then you should install it and you can read about how to configure this plugin here). In .htaccess file just add this line of code:
SetEnv MAGICK_THREAD_LIMIT 1
After adding the code just click “Save changed to .htaccess” and check if the issue is resolved .
Changing theme functions.php file
Actually, we are just going to tell WordPress to use GD as the default WP_Image_Editor class using theme functions.php file. As of WordPress latest update GD has been abstracted and Imagick is used as a default image editor, so going back to the old one seems to fix the issue for everyone.
Recommended: Apparently, there is also a plugin to do so, go here. But if you want to manually edit the file then continue below.
To edit the theme functions.php file just navigate to Appearance > Editor and select Theme Functions (function.php). Once you are there just add this code at the end of the file:
add_filter( ‘wp_image_editors’, ‘change_graphic_lib’ );
function change_graphic_lib($array) {
return array( ‘WP_Image_Editor_GD’, ‘WP_Image_Editor_Imagick’ );
}
Note: Make sure you add this code within the ending PHP sign ( ?>)
This is the most important fix in the guide WordPress shows HTTP error when uploading images but if your issue is still not fixed, continue forward.
Disabling Mod_Security
Note: This method is not advised as it can compromise the security of your WordPress and hosting. Only use this method if you have tried everything else and if disabling this works for you then contact your hosting provider and ask for support.
Again go to your file editor via Yoast SEO > Tools > File Editor and add the following code to your .htaccess file:
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
And click “Save changed to .htaccess.”
Reinstalling the latest version of WordPress
Sometimes this issue can occur because of corrupt WordPress file and any of the above solutions may not work at all, in that case, you have to reinstall the latest version of WordPress:
- Backup your Plugin folder from cPanel (Download them) and then disable them from WordPress. After that remove all of the plugins folders from your server using cPanel.
- Install the standard theme e.g. Twenty sixteen and then remove all other themes.
- From Dashboard > Updates reinstall the latest version of WordPress.
- Upload and activate all the plugins (except the image optimization plugins).
- Install any theme you want.
- Try using the image uploader now.
This will fix WordPress shows HTTP error when uploading images.
Miscellaneous Fixes
- Don’t use apostrophe in the image files names e.g. Aditya-Farrad.jpg
- Try to change the extension of the file.
- Disable all the plugins.
- Make sure your host has the latest version of PHP installed.
- Contact your Hosting Provider for support.
This is the end of this guide and I hope by now you must have fixed the issue WordPress shows HTTP error when uploading images. If you still have any question regarding this post feel free to ask them comments.
Like and share this blog post in the social networks to help spread the word about this problem.