我遇到了完全相同的问题,在探索wordpress源代码之后,文件\'/wp_includes/functions.php\'
, 我的结论是wordpress在默认情况下禁用了对swf和exe文件的上载(请参阅函数get_allowed_mime_types
) , 跳过此操作的唯一方法是启用ALLOW_UNFILTERED_UPLOADS
在里面wp-config
(参见功能wp_upload_bits
).
更新:此外,您必须定义自己的enable_extended_upload
函数可在“上载文件”对话框中识别exe文件。
启用ALLOW_UNFILTERED_UPLOADS
在true中,是swf和exe文件的上载,因为加载的文件不会多于wordpress中默认定义的文件。这意味着如果要加载"zzz" file
, 除非将其设置为自己的,否则它不会加载enable_extended_upload
作用
然后,我将相关函数的最相关代码放入:
function get_allowed_mime_types( $user = null ) {
$t = wp_get_mime_types();
unset( $t[\'swf\'], $t[\'exe\'] );
....
/**
* Filters list of allowed mime types and file extensions.
*
* @since 2.0.0
*
* @param array $t Mime types keyed by the file extension regex corresponding to
* those types. \'swf\' and \'exe\' removed from full list. \'htm|html\' also
* removed depending on \'$user\' capabilities.
* @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user).
*/
return apply_filters( \'upload_mimes\', $t, $user );
}
function wp_check_filetype( $filename, $mimes = null ) {
if ( empty($mimes) )
$mimes = get_allowed_mime_types();
$type = false;
$ext = false;
foreach ( $mimes as $ext_preg => $mime_match ) {
$ext_preg = \'!\\.(\' . $ext_preg . \')$!i\';
if ( preg_match( $ext_preg, $filename, $ext_matches ) ) {
$type = $mime_match;
$ext = $ext_matches[1];
break;
}
}
return compact( \'ext\', \'type\' );
}
function wp_upload_bits( $name, $deprecated, $bits, $time = null ) {
....
$wp_filetype = wp_check_filetype( $name );
if ( ! $wp_filetype[\'ext\'] && ! current_user_can( \'unfiltered_upload\' ) )
return array( \'error\' => __( \'Sorry, this file type is not permitted for security reasons.\' ) );
?>
...