asp.net里怎么把图片传到ashx再上传到服务器

解决方案 »

  1.   

    是选择图片请求ashx然后通过ashx处理在上传吧??
    你是不是要用flash?
      

  2.   


    我用ajax的 然后和其他数据一起传的
    但我不知道怎么弄了
      

  3.   

    1、引入jquery.form.js
    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));
                 }
             }
         }
     }
      

  4.   

    可以用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是存放的路径。  
    希望对你有用。   
      

  5.   

    = = 可以的。   图片是requeat.files  文字那些的信息是 request.form 
    都是根据控件的name获取数据然后上传到数据库或者保存起来  再跳转到显示页面就OK了。  做法一模一样- - 我纠结很久了的。。  
      

  6.   

    图片上传预览及无刷新上传
    话说还有别的数据 你放在表单里 然后在ashx里面取就得啦。
    ashx里面可以得到 HttpContext context对象 还有什么娶不到。
      

  7.   


    ...谢了啊  我主要是为了预览图片问题
    有例子但好多js代码看不懂。。所以就想先看看怎么js传图片到ashx里处理
      

  8.   

     = = 都是坑爹的预览图片。  
    我是要进行组合操作。  如果你只是上传时候为了看的话   用这个方法。  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)”
      

  9.   


    目前知道的浏览器。:   不支持的IE。GOOGLE.    支持的搜狗   TT浏览器。
    如果说是要做支持的话。    可以考虑用JS控件来进行显示。   我只是后台在用  没必要这样弄。 
      

  10.   

    可以用input file控件的postfile属性,把文件传给ashx