WordPress 6.5.2 — загрузка и вставка zip файлов в пост

Понадобилось прикрепить zip файл к записи в WordPress. Ранее, на версии 5.x всё работало, потом, после обновления ОС Ubuntu сервера и WordPress до версии 6.x — перестало.

Рецепт обыкновенный в functions.php темы добавить фильтр:

function modify_upload_mimes ( $mimes_types ) {
    // add your extension to the mimes array as below
    $mimes_types['zip'] = 'application/x-zip-compressed';
    //$mimes_types['zip'] = 'application/zip';
    $mimes_types['gz'] = 'application/x-gzip';
	$mimes_types['xml'] = 'text/xml';
    return $mimes_types;
}
add_filter( 'upload_mimes', 'modify_upload_mimes', 99 );

В старой версии (а может причина не в версии WP) отрабатывала строчка:

$mimes_types['zip'] = 'application/zip';

После обновления — нет. Поменял её на:

$mimes_types['zip'] = 'application/x-zip-compressed';

И всё снова заработало.

Также есть плагин WP Add Mime Types, работоспособность не проверял, но вроде грамотная штука — https://ru.wordpress.org/plugins/wp-add-mime-types/

В Readme данного плагина есть выдержка:

= How to check the uploaded file type from Media. =
WordPress recognizes the file mime type by finfo_file function (wp-includes/functions.php). However, sometimes, the standard MIME type of a file and the MIME type of a WordPress-recognized file are different. By enabling both this option (in setting menu) and the «Enable the attempt to determine the real file type of a file by WordPress core.», the file type is displayed if it is from Media. PLEASE keep in mind that a file uploads are stopped while they are being processed if the both of two options are enabled. Therefore, be sure to disable this debugging option after debugging.


Интересно что сам загружаемый файл я проверил на mime тип и выдавало:

user@server:/home/administrator# file --mime-type 1.zip
/1.zip: application/zip

Или определение mime type с помощью PHP:

<?php
echo mime_content_type('./1.zip');
?>

user@server:/# php ./test_mime.php
application/zip

Но загрузка в WordPress не работала, а данная опция в wp-config.php не решала проблему:

define('ALLOW_UNFILTERED_UPLOADS', true);

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Яндекс.Метрика