admin管理员组

文章数量:1289880

I cannot upload .zip files to my Wordpress network, despite making IMHO everything that is needed. I am still hit by this irritating error.

Details:

  1. I am a super-admin in my network.
  2. The ALLOW_UNFILTERED_UPLOADS flag is set to true
  3. Custom hook of $existing_mimes['zip'] = 'application/zip'; is added
  4. Uploading .zip files is allowed in my network:

Here is entire code of my hook:

function so_387865_custom_upload_mimes ( $existing_mimes ) {
    $existing_mimes['epub'] = 'application/epub+zip';
    $existing_mimes['mobi'] = 'application/x-mobipocket-ebook';
    $existing_mimes['zip'] = 'application/zip';
 
    return $existing_mimes;
}
 
add_filter('upload_mimes', 'so_387865_custom_upload_mimes');

I thought that maybe there's something wrong with the hook, so I have installed the Enhanced Media Library extension (as suggested in here). All for nothing, as it clearly shows that this MIME type is added:

What else should I do in order to be able to upload .zip files? I am seriously lost!

EDIT: As suggested in here, this custom hook is added directly (custom_hooks.php file in wp-content/mu-plugins/ folder). While most guides in the net says about adding custom mimes directly in the theme's code. Maybe this is a problem?

I cannot upload .zip files to my Wordpress network, despite making IMHO everything that is needed. I am still hit by this irritating error.

Details:

  1. I am a super-admin in my network.
  2. The ALLOW_UNFILTERED_UPLOADS flag is set to true
  3. Custom hook of $existing_mimes['zip'] = 'application/zip'; is added
  4. Uploading .zip files is allowed in my network:

Here is entire code of my hook:

function so_387865_custom_upload_mimes ( $existing_mimes ) {
    $existing_mimes['epub'] = 'application/epub+zip';
    $existing_mimes['mobi'] = 'application/x-mobipocket-ebook';
    $existing_mimes['zip'] = 'application/zip';
 
    return $existing_mimes;
}
 
add_filter('upload_mimes', 'so_387865_custom_upload_mimes');

I thought that maybe there's something wrong with the hook, so I have installed the Enhanced Media Library extension (as suggested in here). All for nothing, as it clearly shows that this MIME type is added:

What else should I do in order to be able to upload .zip files? I am seriously lost!

EDIT: As suggested in here, this custom hook is added directly (custom_hooks.php file in wp-content/mu-plugins/ folder). While most guides in the net says about adding custom mimes directly in the theme's code. Maybe this is a problem?

Share Improve this question edited Jul 4, 2021 at 11:41 trejder asked Jul 2, 2021 at 18:47 trejdertrejder 3325 silver badges22 bronze badges 5
  • 1 I know I've had issues in the past using a MIME type different from the one WordPress was expecting. But application/zip looks pretty standard to my eye. Have you tried giving your add_filter() call a higher priority (ie, change it to add_filter('upload_mimes', 'so_387865_custom_upload_mimes', 20 );)? – Pat J Commented Jul 3, 2021 at 2:09
  • As for your suggestion, either I missing something or you made it exactly opposite. Codex says: "Lower numbers correspond with earlier execution". So I should rather go with 1 not 20 in order to give in higher priority. Anyway, nothing helped, neither 20 nor 1. But... As for my question. It seems it is off-topic, because this clearly is some bug in Gutenberg's File block type. I can upload these files without any problems into my Media section of the very same files. Only direct upload to File block fails. – trejder Commented Jul 4, 2021 at 11:48
  • It's a bit confusing. I think of the number as a weight: a higher number is heavier, and therefore later. The higher the number, the later the execution; if a function at priority 1 returns foo and one at priority 100 returns bar, then WP will receive the later one and it'll be bar. – Pat J Commented Jul 4, 2021 at 19:48
  • 1 There is an open issue for that: core.trac.wordpress/ticket/40175 – funkysoul Commented Jul 5, 2021 at 5:00
  • @funkysoul Yeap, just came here to report this as well. – trejder Commented Jul 5, 2021 at 8:56
Add a comment  | 

1 Answer 1

Reset to default 4

The issue has nothing to do with the source code of a theme or plugin or with the configuration of Wordpress. It is:

  • a 6+ months old bug in File block in Gutenberg that narrows down to
  • a 4+ years old bug in core Wordpress.

No solution exists for the moment, except for uploading files via Media section of Wordpress Dasboard. As file upload through that way are 100% working without any problems.

本文标签: hooksWhat conditions must be met in order to upload zip file to a multisite Wordpress installation