从HTML到数据库获取img [英] Get img from HTML to database

查看:269
本文介绍了从HTML到数据库获取img的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hej agian

我试图在将其上传到我的数据库之前预览我的图像,所以我使用javascript它的工作与HTML img但不是asp图像。



所以现在我试图将图像从html标签img保存到我的数据库中。

问题我不能抓住元素img!在代码behinde

有没有可能的方式存储在我的数据库中_



我尝试过:



函数showpreview(输入){



if(input.files&& input.files [ 0]){



var reader = new FileReader();

reader.onload = function(e){

$('#imgpreview')。css('visibility','visible');

$('#imgpreview')。attr('src',e.target.result) ;

}

reader.readAsDataURL(input.files [0]);

}



}

hej agian
im trying to preview my image before uploading it to my db , so i used javascript its work with html img but not asp image .

so now im trying to save image into my database from html tag img.
the problem i cant catch the element img ! in code behinde
is there any possible way to store in my database_

What I have tried:

function showpreview(input) {

if (input.files && input.files[0]) {

var reader = new FileReader();
reader.onload = function (e) {
$('#imgpreview').css('visibility', 'visible');
$('#imgpreview').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}

}

推荐答案

('#imgpreview')。css('visibility','visible');
('#imgpreview').css('visibility', 'visible');


('#imgpreview')。attr('src',e.target.result);

}

reader.readAsDataURL(input.fi les [0]);

}



}
('#imgpreview').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}

}


你无法获取内容图像标签,img或asp:图像。如果需要,您可以显示预览,但是您必须将文件作为表单提交的一部分提交并将其作为普通文件阅读。



Googleasp。 net upload image file你会找到如何做到这一点的例子。



You can't get the content of an image tag, img or asp:Image. You can show the preview if you want, but you have to submit the file as part of a form submission and read it as a normal file.

Google "asp.net upload image file" and you'll find examples of how to do this.

<asp:FileUpload ID="myFile" runat="server" onchange="showpreview(this);" />

<img id="imgpreview" />

<asp:Button ID="btnSubmit" OnClick="btnSubmit_Click" runat="server" />

<script type="text/javascript">
    function showpreview(input) {

        if (input.files && input.files[0]) {

            var reader = new FileReader();
            reader.onload = function (e) {


这篇关于从HTML到数据库获取img的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆