1

我想在我的 HTML Purifier 过滤器中允许图像。不幸的是,它们仍在被过滤。这段代码有什么问题?

$config->set('HTML.Doctype', 'XHTML 1.0 Transitional');
$config->set('URI.DisableExternalResources', false);
$config->set('URI.DisableResources', false);
$config->set('HTML.Allowed', 'u,p,b,i,span[style],p,strong,em,li,ul,ol,div[align],br,img');

谢谢你的帮助。

4

4 回答 4

2

您需要允许 src 和 alt 属性。如果您未能允许元素的必需属性,HTML Purifier 可能会警告您/

于 2010-10-01T17:06:12.353 回答
2

将这行代码添加到您的代码中应该可以解决问题:

$config->set('HTML.AllowedAttributes', 'src, height, width, alt');
于 2014-06-12T16:33:53.043 回答
1

要接受 b64 图像,您必须添加新的 URIScheme:

 if(!class_exists("HTMLPurifier_URIScheme_data")){
        class HTMLPurifier_URIScheme_data extends HTMLPurifier_URIScheme {

            public $default_port = null;
            public $browsable = false;
            public $hierarchical = true;

            public function validate(&$uri, $config, $context) {
                return true;
            }

        }
    }

HTMLPurifier_URISchemeRegistry::instance()->register("data", new HTMLPurifier_URIScheme_data());

来源:http ://htmlpurifier.org/phorum/read.php?3,4316,4318,quote=1

编写此代码的“尼克”说必须设置:

$browsable = true;
$hierarchical = false;

但就我而言,我没有。

于 2018-02-05T18:03:43.407 回答
0

在发布数据(inline src="data:image/png;base64,....)或您的链接时, HTML Purifier seekhttp://https://after src="which 可能会丢失。希望这对您也有用,因为它对我有用。

于 2017-10-30T16:29:21.000 回答