为媒体添加新的 MIME 类型
Add new mime type for media
我想通过此代码将一些 dfxp 文件上传到媒体:
if ( !function_exists('media_handle_upload') ) {
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
}
$id = media_handle_sideload(array('name' =>'test.dfxp', 'tmp_name' =>****/test.dfxp' ));
但是我得到这个错误:
Sorry, this file type is not permitted for security reasons.
即使我将此函数放在代码之上以添加 mime 类型:
function custom_upload_mimes( $existing_mimes ) {
// add webm to the list of mime types
$existing_mimes['dfxp'] = 'application/dfxp';
// return the array back to the function with our added mime type
return $existing_mimes;
}
add_filter('upload_mimes', 'custom_upload_mimes');
是的,我检查了默剧并找到了它。
我该如何解决这个问题?
我不认为有 mime 类型叫做 'application/dfxp' 试试这个
$existing_mimes['dfxp'] = 'application/xml';
代替
$existing_mimes['dfxp'] = 'application/dfxp';
我想通过此代码将一些 dfxp 文件上传到媒体:
if ( !function_exists('media_handle_upload') ) {
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
}
$id = media_handle_sideload(array('name' =>'test.dfxp', 'tmp_name' =>****/test.dfxp' ));
但是我得到这个错误:
Sorry, this file type is not permitted for security reasons.
即使我将此函数放在代码之上以添加 mime 类型:
function custom_upload_mimes( $existing_mimes ) {
// add webm to the list of mime types
$existing_mimes['dfxp'] = 'application/dfxp';
// return the array back to the function with our added mime type
return $existing_mimes;
}
add_filter('upload_mimes', 'custom_upload_mimes');
是的,我检查了默剧并找到了它。
我该如何解决这个问题?
我不认为有 mime 类型叫做 'application/dfxp' 试试这个
$existing_mimes['dfxp'] = 'application/xml';
代替
$existing_mimes['dfxp'] = 'application/dfxp';