How can I configure HTML Purifier to allow data URIs for image src?

回眸只為那壹抹淺笑 提交于 2019-12-06 23:49:45

问题


How can I allow base64 data for the the src attribute of image tags? I see code like this:

$config->set('URI.AllowedSchemes', array('http' => true, 'https' => true, 'mailto' => true, 'ftp' => true, 'nntp' => true, 'news' => true, 'data' => true));

In this case, is it data => true which allows the base64? And if so, how can I allow base64 data only for the src attribute of the img tag? (I do not want to allow data URIs in other situations.)

I thought of doing something like:

$ def-> addAttribute ('a', 'target', 'Enum # _blank, _self, _target, _top');     

But in my case like this:

$ def-> addAtribute ('img', 'src', 'Enum # data, http, https, ...);

Is this possible?


回答1:


Easy: just only have data in your allowed schemes:

$config->set('URI.AllowedSchemes', array('data' => true));


来源:https://stackoverflow.com/questions/26524222/how-can-i-configure-html-purifier-to-allow-data-uris-for-image-src

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!