如何修复WordPress中的HTTP图像上传错误

Are you seeing the HTTP error while uploading media in WordPress? This error usually occurs when you are uploading an image or other files to WordPress using the built-in media uploader. In this article, we will show you how to easily fix the HTTP image upload error in WordPress.

在WordPress中上传媒体时是否看到HTTP错误? 当您使用内置媒体上传器将图像或其他文件上传到WordPress时,通常会发生此错误。 在本文中,我们将向您展示如何轻松解决WordPress中的HTTP图片上传错误。

How to fix http error when uploading images in WordPress
是什么原因导致WordPress媒体上传期间出现HTTP错误? (What Causes HTTP Error During Media Upload in WordPress?)

There are a number of things that could lead to a HTTP error when you are trying to upload files using the WordPress media uploader. Basically, WordPress is unable to figure out the cause and that’s why it displays the generic ‘HTTP error’ message.

当您尝试使用WordPress媒体上传器上传文件时,有很多情况可能导致HTTP错误。 基本上,WordPress无法找出原因,这就是为什么它显示通用的“ HTTP错误”消息。

HTTP Error

The frustrating part is that this error message doesn’t give you any clue as to what may have caused it. This means that you will have to try different solutions to find the cause and fix the error.

令人沮丧的部分是,此错误消息无法为您提供任何可能的原因提示。 这意味着您将不得不尝试不同的解决方案以找到原因并修复错误。

That being said, let’s take a look at how to troubleshoot and fix the HTTP error during media upload in WordPress.

话虽如此,让我们看一下如何在WordPress中上传媒体期间解决和修复HTTP错误。

1.确保HTTP错误不是临时的 (1. Make Sure The HTTP Error is Not Temporary)

First, you should wait a few minutes and then try uploading your image file again. This error is sometimes caused by unusual traffic and low server resources, which are automatically fixed on most WordPress hosting servers.

首先,您应该等待几分钟,然后尝试再次上传图像文件。 有时,此错误是由异常流量和服务器资源不足引起的,这些错误会在大多数WordPress托管服务器上自动修复。

If that doesn’t work, then you may want to try uploading a different image file. If the other file uploads successfully, then try saving your original image file to a smaller size and retry uploading.

如果这不起作用,那么您可能想要尝试上传其他图像文件。 如果其他文件成功上传,请尝试将原始图像文件保存为较小的大小,然后重试上传。

Lastly, you may want to try saving the file to a different format. For example, change jpeg to png using an image editing software. After that, retry uploading the file.

最后,您可能想尝试将文件保存为其他格式。 例如,使用图像编辑软件将jpeg更改为png。 之后,重试上传文件。

If all these steps result in the HTTP error, then this means that the error is not caused by a temporary glitch and definitely needs your immediate attention.

如果所有这些步骤均导致HTTP错误,则意味着该错误不是由临时故障引起的,因此绝对需要您立即注意。

2.增加WordPress内存限制 (2. Increase WordPress Memory Limit)

The most common cause of this error is lack of memory available for WordPress to use. To fix this, you need to increase the amount of memory PHP can use on your server.

导致此错误的最常见原因是WordPress无法使用可用的内存。 要解决此问题,您需要增加PHP在服务器上可以使用的内存量。

You can do this by adding the following code to your wp-config.php file.

您可以通过将以下代码添加到wp-config.php文件中来实现


define( 'WP_MEMORY_LIMIT', '256M' );

This code increases the WordPress memory limit to 256MB, which would be enough to fix any memory limit issues.

此代码将WordPress内存限制增加到256MB,足以解决任何内存限制问题。

File uploaded successfully
3.更改WordPress使用的图像编辑器库 (3. Change Image Editor Library Used by WordPress)

WordPress runs on PHP which uses two modules to handle images. These modules are called GD Library and Imagick. WordPress may use either one of them depending on which one is available.

WordPress在PHP上运行,该PHP使用两个模块来处理图像。 这些模块称为GD Library和Imagick。 WordPress可以使用其中之一,具体取决于哪一个可用。

However, Imagick is known to often run into memory issues causing the http error during image uploads. To fix this, you can make the GD Library your default image editor.

但是,众所周知,Imagick经常会遇到内存问题,从而在图像上传期间导致http错误。 要解决此问题,您可以将GD Library设置为默认的图像编辑器。

You can do this by simply adding this code to your theme’s functions.php file or a site-specific plugin.

您只需将代码添加到主题的functions.php文件或特定站点的插件中即可


function wpb_image_editor_default_to_gd( $editors ) {
	$gd_editor = 'WP_Image_Editor_GD';
	$editors = array_diff( $editors, array( $gd_editor ) );
	array_unshift( $editors, $gd_editor );
	return $editors;
}
add_filter( 'wp_image_editors', 'wpb_image_editor_default_to_gd' );

After adding this code, you can retry uploading files using the media uploader. If this doesn’t solve the issue, then you can remove this code and try other methods described in this article.

添加此代码后,您可以使用媒体上传器重试上传文件。 如果这样做不能解决问题,则可以删除此代码,然后尝试本文介绍的其他方法。

4.使用.htaccess方法 (4. Using The .htaccess Method)

This method allows you to control how Imagick uses server resources. Many shared hosting providers limit Imagick’s ability to use multiple threads for faster image processing. However, this would result in you seeing the http error when uploading images.

此方法使您可以控制Imagick如何使用服务器资源。 许多共享的托管服务提供商限制了Imagick使用多个线程进行更快的图像处理的能力。 但是,这将导致您在上传图像时看到http错误。

An easy fix is be to add the following code in your .htaccess file:

一个简单的解决方法是在.htaccess文件中添加以下代码:


SetEnv MAGICK_THREAD_LIMIT 1

This code simply limits Imagick to use a single thread to process images.

该代码仅限制Imagick使用单个线程来处理图像。

We hope this article helped you fix the HTTP error during media upload in WordPress. You may also want to see our WordPress troubleshooting guide as well as the ultimate list of most common WordPress errors and how to fix them.

我们希望本文能帮助您解决在WordPress中上传媒体期间的HTTP错误。 您可能还需要查看我们的WordPress故障排除指南以及最常见的WordPress错误的最终列表以及如何修复它们。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-fix-the-http-image-upload-error-in-wordpress/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值