WordPress不允许上传rar文件的解决方法


今天Blog刚刚重新搭建好,使用的WordPress2.9.1

再写第二篇文章的时候就发现不让上传RAR文件。。。

无语 。。。

解决方案:

打开文件 wp-content/wp-includes/functions.php文件

找到get_allowed_mime_types方法:

发现他就然就是没有rar:

/**
* Retrieve list of allowed mime types and file extensions.
*
* @since 2.8.6
*
* @return array Array of mime types keyed by the file extension regex corresponding to those types.
*/
function get_allowed_mime_types() {
static $mimes = false;

if ( !$mimes ) {
// Accepted MIME types are set here as PCRE unless provided.
$mimes = apply_filters( ‘upload_mimes’, array(
‘jpg|jpeg|jpe’ => ‘image/jpeg’,
‘gif’ => ‘image/gif’,
‘png’ => ‘image/png’,
‘bmp’ => ‘image/bmp’,
‘tif|tiff’ => ‘image/tiff’,
‘ico’ => ‘image/x-icon’,
‘asf|asx|wax|wmv|wmx’ => ‘video/asf’,
‘avi’ => ‘video/avi’,
‘divx’ => ‘video/divx’,
‘flv’ => ‘video/x-flv’,
‘mov|qt’ => ‘video/quicktime’,
‘mpeg|mpg|mpe’ => ‘video/mpeg’,
‘txt|c|cc|h’ => ‘text/plain’,
‘rtx’ => ‘text/richtext’,
‘css’ => ‘text/css’,
‘htm|html’ => ‘text/html’,
‘mp3|m4a’ => ‘audio/mpeg’,
‘mp4|m4v’ => ‘video/mp4’,
‘ra|ram’ => ‘audio/x-realaudio’,
‘wav’ => ‘audio/wav’,
‘ogg’ => ‘audio/ogg’,
‘mid|midi’ => ‘audio/midi’,
‘wma’ => ‘audio/wma’,
‘rtf’ => ‘application/rtf’,
‘js’ => ‘application/javascript’,
‘pdf’ => ‘application/pdf’,
‘doc|docx’ => ‘application/msword’,
‘pot|pps|ppt|pptx’ => ‘application/vnd.ms-powerpoint’,
‘wri’ => ‘application/vnd.ms-write’,
‘xla|xls|xlsx|xlt|xlw’ => ‘application/vnd.ms-excel’,
‘mdb’ => ‘application/vnd.ms-access’,
‘mpp’ => ‘application/vnd.ms-project’,
‘swf’ => ‘application/x-shockwave-flash’,
‘class’ => ‘application/java’,
‘tar’ => ‘application/x-tar’,
‘zip’ => ‘application/zip’,
‘gz|gzip’ => ‘application/x-gzip’,
‘exe’ => ‘application/x-msdownload’,
// openoffice formats
‘odt’ => ‘application/vnd.oasis.opendocument.text’,
‘odp’ => ‘application/vnd.oasis.opendocument.presentation’,
‘ods’ => ‘application/vnd.oasis.opendocument.spreadsheet’,
‘odg’ => ‘application/vnd.oasis.opendocument.graphics’,
‘odc’ => ‘application/vnd.oasis.opendocument.chart’,
‘odb’ => ‘application/vnd.oasis.opendocument.database’,
‘odf’ => ‘application/vnd.oasis.opendocument.formula’,
) );
}

return $mimes;
}

然后在其中加入’rar’ => ‘application/rar’,问题解决,可以上传RAR了,不知道是不是Wordpress的Bug。

看它这个方法里面都有rar:

/**
* Retrieve the file type based on the extension name.
*
* @package WordPress
* @since 2.5.0
* @uses apply_filters() Calls ‘ext2type’ hook on default supported types.
*
* @param string $ext The extension to search.
* @return string|null The file type, example: audio, video, document, spreadsheet, etc. Null if not found.
*/
function wp_ext2type( $ext ) {
$ext2type = apply_filters(‘ext2type’, array(
‘audio’ => array(‘aac’,’ac3′,’aif’,’aiff’,’mp1′,’mp2′,’mp3′,’m3a’,’m4a’,’m4b’,’ogg’,’ram’,’wav’,’wma’),
‘video’ => array(‘asf’,’avi’,’divx’,’dv’,’mov’,’mpg’,’mpeg’,’mp4′,’mpv’,’ogm’,’qt’,’rm’,’vob’,’wmv’, ‘m4v’),
‘document’ => array(‘doc’,’docx’,’pages’,’odt’,’rtf’,’pdf’),
‘spreadsheet’ => array(‘xls’,’xlsx’,’numbers’,’ods’),
‘interactive’ => array(‘ppt’,’pptx’,’key’,’odp’,’swf’),
‘text’ => array(‘txt’),
‘archive’ => array(‘tar’,’bz2′,’gz’,’cab’,’dmg’,’rar’,’sea’,’sit’,’sqx’,’zip’),
‘code’ => array(‘css’,’html’,’php’,’js’),
));
foreach ( $ext2type as $type => $exts )
if ( in_array($ext, $exts) )
return $type;
}

奇怪。嘎嘎。

不过,顶一下,wordpress真的很好用~,比以前好用了很多很多~


发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

验证码 * Time limit is exhausted. Please reload CAPTCHA.