Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Wordpress中上载PowerPoint幻灯片文件?_Wordpress - Fatal编程技术网

如何在Wordpress中上载PowerPoint幻灯片文件?

如何在Wordpress中上载PowerPoint幻灯片文件?,wordpress,Wordpress,我有一些PowerPoint幻灯片文件,.ppsx,mime类型为application/vnd.openxmlformats of cedocument.presentationml.slideshow,我想上传到WordPress。但是,当我尝试将其上载到媒体浏览器时,会出现错误“对不起,出于安全原因,不允许使用此文件类型。” 尽管.ppsx文件在允许的文件类型和mimetype列表中,这一点仍然存在。上载文件时,WordPress会在wp include/functions.php:250

我有一些PowerPoint幻灯片文件,.ppsx,mime类型为
application/vnd.openxmlformats of cedocument.presentationml.slideshow
,我想上传到WordPress。但是,当我尝试将其上载到媒体浏览器时,会出现错误“对不起,出于安全原因,不允许使用此文件类型。”


尽管.ppsx文件在允许的文件类型和mimetype列表中,这一点仍然存在。

上载文件时,WordPress会在
wp include/functions.php:2503
中的函数中对文件进行一些安全检查。这些检查的一部分是使用PHP函数用PHP检测到的mimetype验证文件的给定mimetype

然而,
finfo_file()
并不总是准确的,其结果通常依赖于操作系统。在.ppsx文件的特定情况下,
finfo_file()
可以将mimetype读取为
application/vnd.openxmlformats oficedocument.presentationml.presentation
。WordPress认为这是一个潜在的安全风险,因为它与该文件扩展名的给定mimetype不匹配,并关闭了上载

wp\u check\u filetype\u和_ext()
还有一个过滤器,我们可以利用它:

function my_check_filetype_and_ext( $info, $file, $filename, $mimes, $real_mime )
{
    if ( empty( $check['ext'] ) && empty( $check['type'] ) )
    {
        $secondaryMimetypes = ['ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation'];

        // Run another check, but only for our secondary mime and not on core mime types.
        remove_filter( 'wp_check_filetype_and_ext', 'my_check_filetype_and_ext', 99, 5 );
        $info = wp_check_filetype_and_ext( $file, $filename, $secondaryMimetypes );
        add_filter( 'wp_check_filetype_and_ext', 'my_check_filetype_and_ext', 99, 5 );
    }

    return $info;
}
add_filter( 'wp_check_filetype_and_ext', 'my_check_filetype_and_ext', 99, 5 );

在vanilla WordPress中,一个文件类型不能有多个mimetype。如果第一组文件类型对失败,则上述筛选器将再次运行第二组文件类型/mimetype对的mimetype检查。通过允许.ppsx文件具有演示文稿mimetype,您现在可以上载.ppsx文件了

您需要在configure.php文件中添加一些代码来上载任何类型的

define( 'ALLOW_UNFILTERED_UPLOADS', true );
将其添加到configure.php文件中,您将能够上传任何文件格式

或者您也可以按照此操作

在$secondaryMimetypes声明中使用小写“t”,但在$info中使用大写。不过还是要谢谢你。