【问题标题】:OTF font not uploded in Wordpress在 Wordpress 中未上传 OTF 字体
【发布时间】:2017-11-24 07:29:51
【问题描述】:

我想在 WordPress 仪表板中上传自定义字体。当我尝试上传字体文件时,它显示错误:

Sorry, this file type is not permitted for security reasons.

然后我使用以下代码允许所有文件使用字体:

  add_filter('upload_mimes', 'add_custom_upload_mimes');
  function add_custom_upload_mimes($existing_mimes) {
    $existing_mimes['otf'] = 'application/x-font-opentype';
    $existing_mimes['woff'] = 'application/x-font-woff';
    $existing_mimes['ttf'] = 'application/x-font-ttf';
    $existing_mimes['svg'] = 'image/svg+xml';
    $existing_mimes['eot'] = 'application/vnd.ms-fontobject';
    return $existing_mimes;
  }

现在所有类型的字体都已上传,但当我上传 .otf 字体时,它显示相同的错误。

请帮我解决这个问题。提前致谢。

【问题讨论】:

    标签: wordpress fonts wordpress-theming mime-types


    【解决方案1】:

    我使用了以下代码,并且运行正常。

        add_filter('upload_mimes', 'custom_upload_mimes');
        function custom_upload_mimes ( $existing_mimes ) {
    
            $existing_mimes['ttf'] = 'application/x-font-ttf';
            $existing_mimes['woff'] = 'application/x-font-woff';
            $existing_mimes['woff2'] = 'application/x-font-woff2';
            $existing_mimes['otf'] = 'application/x-font-otf';
            return $existing_mimes;
        }
    

    【讨论】:

      【解决方案2】:

      Blow 是解决此问题的步骤。

      打开 WordPress 安装的 wp-config.php 文件,并在它上面写着 /* 的行上方打开,停止编辑!快乐的博客。 */ 在任何地方添加以下代码:

      define('ALLOW_UNFILTERED_UPLOADS', true);
      

      参考:https://tribulant.com/blog/wordpress/how-to-fix-sorry-this-file-type-is-not-permitted-for-security-reasons/

      【讨论】:

        【解决方案3】:

        你已经很久没有发这个帖子了。但我正在使用一个名为“WP Add Mime Types”的插件。

        作为插件设置(设置 -> Myme 类型设置)中的一个值,我添加了这个:otf = application/x-font-opentype

        它对我有用:)

        【讨论】:

          【解决方案4】:

          尝试使用

          $existing_mimes['otf'] = 'font/otf';
          

          $existing_mimes['otf'] = 'application/font-sfnt';
          

          【讨论】:

            猜你喜欢
            • 2019-08-05
            • 2015-04-22
            • 2012-11-03
            • 2016-03-22
            • 1970-01-01
            • 2012-05-21
            • 2015-08-10
            • 2011-03-15
            • 1970-01-01
            相关资源
            最近更新 更多