这个发布信息的页面 我是将所有数据发送到一般处理文件 ashx中进行无刷新添加信息,,,此处上传图片用的是
前台的 <input type="file" /> 控件
我在ashx里面可以获取到本地的路径 请问该这么保存图片到服务器呢????
------解决方案--------------------------------------------------------
HttpPostedFile fileUpload = context.Request.Files[0];
fileUpload.SaveAs(Server.MapPath("~/" + Path.GetFileName(fileUpload.FileName)))
你不能使用客户端路径进行保存的。
另外
<input type="file" name="x1"/>要加name
------解决方案--------------------------------------------------------
- C# code
HttpFileCollection uploadFiles = System.Web.HttpContext.Current.Request.Files;//可以得到所有准备上传的文件 HttpPostedFile theFile;///HttpPostedFile:提供对客户端已上载的单独文件的访问 //string abc = "fdsfdsfdfwewru"; for (int i = 0; i < uploadFiles.Count -1; i++) { theFile = uploadFiles[i]; string name = Path.GetFileName(theFile.FileName);///获取上载文件的文件名称 ///FileName:传回client端上传文件的名称,具有完整的路径。如c:\aa\aa.txt。|||Path.GetFileNam根据路径取得带扩展名的文件名 if (name!=null) { if (theFile.ContentLength>60000) { Page.ClientScript.RegisterStartupScript(this.GetType(), "上传失败!", "alert('您上传的图片太大了')", true); return; } else { theFile.SaveAs(MapPath("image/") + name); Page.ClientScript.RegisterStartupScript(this.GetType(), "上传成功", "confirm('你上传成功')", true); } }
------解决方案--------------------------------------------------------
不可能实现的东东。
------解决方案--------------------------------------------------------
看看一楼的博客 找上传的文章。
FORM提交
------解决方案--------------------------------------------------------
想实现无刷新 可以考虑使用jq+flash 插件推荐uploadify
------解决方案--------------------------------------------------------
plupload这玩意也不错