asp.net里怎么把图片传到ashx再上传到服务器上 asp.net里怎么把图片传到ashx再上传到服务器 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是选择图片请求ashx然后通过ashx处理在上传吧??你是不是要用flash? 我用ajax的 然后和其他数据一起传的但我不知道怎么弄了 1、引入jquery.form.js2、JS方法function upLoadFile(){ var options = { type: "POST", url: 'Files.ashx', success: showResponse }; // 将options传给ajaxForm $('#myForm').ajaxSubmit(options);//myForm为你页面的form的id }//上传成功后事件function showResponse(){ alert("上传成功!");} 3、Files.ashx相关代码public void ProcessRequest(HttpContext context){ HttpFileCollection files = context.Request.Files; if (files.Count > 0) { Random rnd = new Random(); for (int i = 0; i < files.Count; i++) { HttpPostedFile file = files[i]; if (file.ContentLength > 0) { string fileName = file.FileName; string extension = Path.GetExtension(fileName); int num = rnd.Next(5000, 10000); string path = "file/" + num.ToString() + extension; file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path)); } } } } 可以用from表单进行提交。 LZ的想法是无刷新将图片提交上去。跟我的问题基本是相似的。 <form action="ReAdd3.aspx" id="form2" method="post" enctype="multipart/form-data" target="upload" ></form><iframe name="upload" style="display:none"></iframe>最好只用html控件 给控件的name赋值 然后就可以到form表单中的action指定页面获取数据了图片的获取:protected void upfile(string filename,string overpath) { if(Request.Files[filename].ContentLength>0){ HttpPostedFile myfile = Request.Files[filename]; myfile.SaveAs(overpath); } }filename 是控件的name overpath是存放的路径。 希望对你有用。 = = 可以的。 图片是requeat.files 文字那些的信息是 request.form 都是根据控件的name获取数据然后上传到数据库或者保存起来 再跳转到显示页面就OK了。 做法一模一样- - 我纠结很久了的。。 图片上传预览及无刷新上传话说还有别的数据 你放在表单里 然后在ashx里面取就得啦。ashx里面可以得到 HttpContext context对象 还有什么娶不到。 ...谢了啊 我主要是为了预览图片问题有例子但好多js代码看不懂。。所以就想先看看怎么js传图片到ashx里处理 = = 都是坑爹的预览图片。 我是要进行组合操作。 如果你只是上传时候为了看的话 用这个方法。 JS里面 在file控件的onchang事件里面 function display3(abc) { document.getElementById("ImgEsc").src = abc; }imgesc是image控件的id 后台这样绑定 FileAnsIcon.Attributes.Add("onchange", "display1(this.value);");或者在控件后面加 onchange=“display3(this.value)” 目前知道的浏览器。: 不支持的IE。GOOGLE. 支持的搜狗 TT浏览器。如果说是要做支持的话。 可以考虑用JS控件来进行显示。 我只是后台在用 没必要这样弄。 可以用input file控件的postfile属性,把文件传给ashx 如何利用url和eval传递多个参数,在线等,很急!! 谁做过测试帐号的程序,或思路? sql server,数据库,access问题,.net HttpRequest怎么把URL信息加载进去 如何将显示的内容换行 怎样才是高手 SiteMap DataSet中的记录删除的问题? 【求助】w3wp.exe发生错误怎么解决 如何用ASP.NET编写上传文件的页面 .net mvc 2.0 重写controller,session的问题 如何根据条件 取出DataTable里的几行数据给另外一个DataTable
你是不是要用flash?
我用ajax的 然后和其他数据一起传的
但我不知道怎么弄了
2、JS方法function upLoadFile()
{
var options = {
type: "POST",
url: 'Files.ashx',
success: showResponse
}; // 将options传给ajaxForm
$('#myForm').ajaxSubmit(options);//myForm为你页面的form的id
}
//上传成功后事件
function showResponse()
{
alert("上传成功!");
} 3、Files.ashx相关代码public void ProcessRequest(HttpContext context)
{
HttpFileCollection files = context.Request.Files;
if (files.Count > 0)
{
Random rnd = new Random();
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i]; if (file.ContentLength > 0)
{
string fileName = file.FileName;
string extension = Path.GetExtension(fileName);
int num = rnd.Next(5000, 10000);
string path = "file/" + num.ToString() + extension;
file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path));
}
}
}
}
跟我的问题基本是相似的。
<form action="ReAdd3.aspx" id="form2" method="post" enctype="multipart/form-data" target="upload" >
</form>
<iframe name="upload" style="display:none"></iframe>最好只用html控件 给控件的name赋值 然后就可以到form表单中的action指定页面获取数据了
图片的获取:protected void upfile(string filename,string overpath)
{
if(Request.Files[filename].ContentLength>0){
HttpPostedFile myfile = Request.Files[filename];
myfile.SaveAs(overpath);
}
}
filename 是控件的name overpath是存放的路径。
希望对你有用。
都是根据控件的name获取数据然后上传到数据库或者保存起来 再跳转到显示页面就OK了。 做法一模一样- - 我纠结很久了的。。
话说还有别的数据 你放在表单里 然后在ashx里面取就得啦。
ashx里面可以得到 HttpContext context对象 还有什么娶不到。
...谢了啊 我主要是为了预览图片问题
有例子但好多js代码看不懂。。所以就想先看看怎么js传图片到ashx里处理
我是要进行组合操作。 如果你只是上传时候为了看的话 用这个方法。 JS里面 在file控件的onchang事件里面
function display3(abc) {
document.getElementById("ImgEsc").src = abc;
}imgesc是image控件的id
后台这样绑定 FileAnsIcon.Attributes.Add("onchange", "display1(this.value);");
或者在控件后面加 onchange=“display3(this.value)”
目前知道的浏览器。: 不支持的IE。GOOGLE. 支持的搜狗 TT浏览器。
如果说是要做支持的话。 可以考虑用JS控件来进行显示。 我只是后台在用 没必要这样弄。