这是我目前拥有的,图片无法加载。我正在尝试使用类似Snapchat的功能来显示我不想保存的图像
echo '<img src="' . $image . '">';
if (unlink($fileLo)){
$mStat = 1;
}else {
$mStat = 0;
}
对于javascript,我这样做是为了防止每5秒右键单击并刷新页面
<script type="text/javascript">
function click (e) {
if (!e)
e = window.event;
if ((e.type && e.type == "contextmenu") || (e.button && e.button == 2) || (e.which && e.which == 3)) {
if (window.opera)
window.alert("");
return false;
}
}
if (document.layers)
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown = click;
document.oncontextmenu = click;
</script>
<meta http-equiv="refresh" content="5" />
答案 0 :(得分:0)
如果你想在页面加载后删除一个文件 - 你可以在页面加载时向php delete函数发出一个AJAX请求来删除图像(刚刚加载页面后),所以文件不会不再存在,但无论如何,图像被保存到浏览器缓存中,因此可以从客户端获取它 - 从浏览器缓存中保存。
此外,由于javascript是客户端,用户可以操作它,用户可以阻止js代码,因此不会发送删除请求。
答案 1 :(得分:0)
您可以在页面加载时获取php中图像的base64,然后在同一个脚本中删除该文件。
然后,您只需将base64内联回显到图像标记。
这样做可以向用户显示图像,同时从服务器中删除。全部使用相同的PHP脚本,不使用ajax调用。