[英]How do I allow images in the HTMLPurifier?
I want to allow images within my HTML Purifier filter. 我想允许图像在我的HTML Purifier过滤器中。 Unfortunately they are still being filtered. 不幸的是,它们仍在被过滤。 WHat is wrong with this code? 这段代码错了吗?
$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');
Thanks for your help. 谢谢你的帮助。
将这行代码添加到您的代码中应该可以解决此问题:
$config->set('HTML.AllowedAttributes', 'src, height, width, alt');
You need to allow the src and alt attributes. 您需要允许src和alt属性。 HTML Purifier should probably warn you if you fail to allow a required attribute for an element/ 如果您未能允许元素/的必需属性,则HTML Purifier可能会警告您
HTML Purifier seek http://
or https://
after src="
which may be missing while posting data (inline src="data:image/png;base64,.... ) or your link. HTML Purifier在src="
之后寻找http://
或https://
,在发布数据(内联src =” data:image / png; base64,....)或您的链接时可能会丢失。 Hope this will work for you too as it worked for me. 希望它也对我有用。
To accept b64 images you must add a new URIScheme: 要接受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());
Source: http://htmlpurifier.org/phorum/read.php?3,4316,4318,quote=1 资料来源: http : //htmlpurifier.org/phorum/read.php?3,4316,4318,quote=1
"Nick", the guy who made this code, said that had to set: 编写此代码的人“ Nick”说必须设置:
$browsable = true;
$hierarchical = false;
But in my case i didn't. 但就我而言,我没有。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.