我正在开发一个网络工具(一个TiddlyWiki Classic插件),contenteditable
其中包含我想通过复制粘贴插入图像的元素;然后它们应该通过(PHP)服务器存储在本地。
除其他外,后端应该通过 url 存储图像,这些图像是通过从网页复制粘贴图像而生成的。我的抓图功能草稿如下:
function loadImageByUrlAndSave($url,$path,$name)
{
$url = filter_var($url,FILTER_SANITIZE_URL); //# not sure if this is really needed
$img = file_get_contents($url);
$type = "png";
//# check for request errors, ensure we got an image, get its type automatically
file_put_contents($path . $name . "." . $type,$img);
};
到目前为止有效;但是,我读过file_get_contents
不鼓励以这种直接的方式使用。我想当它在本地使用并且仅由我使用时,这里唯一的安全问题是避免包含 JavaScript 的图像(我很少听说过这个)。您建议采取哪些安全措施?是否可以从图像中自动删除 JavaScript?它是否在复制粘贴阶段的此工作流程中被删除,以便我完全不用担心?我想避免任何意外行为,因为这可能会损坏我的 TW 中的数据。