简体   繁体   English

上传完成后,媒体库“ HTTP错误”

[英]Media Library “HTTP error” when upload finishes

I host multiple Wordpress sites on a single Ubuntu VPS. 我在单个Ubuntu VPS上托管了多个Wordpress网站。 One of my sites just recently started giving me an "HTTP error" when uploading files to the media library. 我最近的一个站点在将文件上传到媒体库时开始给我一个“ HTTP错误”。

I know this is a common error, but my error happens AFTER the file finishes uploading, and I can see the it there on the server, and that it's the correct size but it's corrupted and won't open. 我知道这是一个常见错误,但是我的错误发生在文件上传完成之后,我可以在服务器上看到它,它的大小正确,但是已损坏,无法打开。 I'm thinking if it was a permissions issue then the file wouldn't be there at all, and the other sites on this server work fine. 我在想如果这是一个权限问题,那么该文件将根本不存在,并且该服务器上的其他站点都可以正常工作。

I've already checked all the configs for nginx, php, and wordpress for file upload size limits and they all seem good. 我已经检查了nginx,php和wordpress的所有配置中的文件上传大小限制,它们看起来都不错。 I never added any new plugins recently. 我最近从未添加任何新插件。

Its the permissions problem, Please set 777 for uploads folder 其权限问题,请为上传文件夹设置777

then the HTTP "Error wont" appear 然后出现HTTP“错误不会”

Its basically due to permission only, your Upload folder doesn't have correct permission. 基本上,由于权限的限制,您的Upload文件夹没有正确的权限。

Put this script file in your Wordpress root dir and execute it.( it will set the permission for all the folders and files) 将此脚本文件放在您的Wordpress根目录中并执行它(它将设置所有文件夹和文件的权限)

fix-wordpress-permissions.sh 修复wordpress-permissions.sh

WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory
WS_GROUP=www-data # <-- webserver group

# reset to safe defaults
find ${WP_ROOT} -exec chown ${WP_OWNER}:${WP_GROUP} {} \;
find ${WP_ROOT} -type d -exec chmod 755 {} \;
find ${WP_ROOT} -type f -exec chmod 644 {} \;

# allow wordpress to manage wp-config.php (but prevent world access)
chgrp ${WS_GROUP} ${WP_ROOT}/wp-config.php
chmod 660 ${WP_ROOT}/wp-config.php

# allow wordpress to manage wp-content
find ${WP_ROOT}/wp-content -exec chgrp ${WS_GROUP} {} \;
find ${WP_ROOT}/wp-content -type d -exec chmod 775 {} \;
find ${WP_ROOT}/wp-content -type f -exec chmod 664 {} \;

I'm not convinced it's a permissions error. 我不认为这是权限错误。 You said it "used to work," so that makes me think it's something else. 您说它“用于工作”,所以让我认为这是另一回事。 Here's something you could try. 您可以尝试以下方法。

WordPress runs on PHP which uses two modules to handle images. WordPress在PHP上运行,该PHP使用两个模块来处理图像。 These modules are called GD Library and Imagick. 这些模块称为GD Library和Imagick。 WordPress may use either one of them depending on which one is available. WordPress可能会使用其中之一,具体取决于哪一个可用。

Imagick, the default, is known to often run into memory issues causing the http error during image uploads. 众所周知,默认情况下,Imagick经常会遇到内存问题,从而在图像上传期间导致http错误。 To fix this, you can change the default image editor to the GD Library by adding this function to your theme's functions.php file or, better, as a custom plugin. 要解决此问题,您可以通过将默认功能添加到主题库的functions.php文件中,或者最好将其添加为自定义插件,来将默认图像编辑器更改为GD Library。

// Change Default Image Editor Library Used by WordPress
function xyz_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', 'xyz_image_editor_default_to_gd' );

Picked up that little trick from WP Beginner: https://www.wpbeginner.com/wp-tutorials/how-to-fix-the-http-image-upload-error-in-wordpress/ (credit where credit is due). 从WP Beginner中挑选了这个小技巧: https : //www.wpbeginner.com/wp-tutorials/how-to-fix-the-http-image-upload-error-in-wordpress/ (应归功于贷方) 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM