【发布时间】:2023-04-03 17:21:01
【问题描述】:
我有一个用于班级项目的假个人资料系统,它需要个人资料图片,并且需要在本地(从您的硬盘驱动器)更改它的选项。我有一个有效的img 标签,它默认保存一个占位符图像,当您单击change picture 时,会打开一个打开文件对话框。我现在需要做的就是使用他们选择的图像设置img 标签的图像链接。这是我目前所拥有的。
<div id="userphoto">
<a><div class="gravatar-wrapper-128"><img id="image" src="http://blog.ramboll.com/fehmarnbelt/wp-content/themes/ramboll2/images/profile-img.jpg" alt="" class="logo" width="120" height="120"></div></a>
<div class="change-picture-slide" style="top: 30px;">
<input accept="image/*" type="file" id="upload" name="upload" style="visibility: hidden; width: 1px; height: 1px" />
<a href="" onclick="changePicture(); return false">Change Picture</a>
</div>
</div>
<script>
function changePicture() {
//open the open file dialog
document.getElementById('upload').click();
var link = document.getElementById('upload').url;
//change picture
var img = document.getElementById("image");
img.src = link;
}
</script>
知道这是不可能的,我如何将用户选择的图像匿名上传到imgur并使用此链接?
【问题讨论】:
-
这是不可能的,因为这将是一个主要的安全问题。请参阅此现有问题:stackoverflow.com/questions/15201071/…
标签: javascript html image image-uploading