多文件上传问题

时间:2012-08-13 12:25:18

标签: asp.net file-upload

我使用multi file upload在ASP.Net中上传文件而没有任何问题。但是现在我想添加更多功能,比如创建缩略图,而下面的代码是我的代码:

try
        {
            string _path = "~/photos/realimg/";
            string _thumPath = "~/photos/thumbimg/";
            // Get the HttpFileCollection
            HttpFileCollection hfc = Request.Files;
            for (int i = 0; i < hfc.Count; i++)
            {
                HttpPostedFile hpf = hfc[i];
                if (hpf.ContentLength > 0)
                {
                    _path += System.IO.Path.GetFileName(hpf.FileName);
                    _thumPath += System.IO.Path.GetFileName(hpf.FileName.Insert(0, "thumb_"));
                    hpf.SaveAs(Server.MapPath(_path));
                    SavePicPath(_path);
                    System.Drawing.Image realImg = System.Drawing.Image.FromFile(Server.MapPath(_path));

                    Int32 rH = realImg.Height;
                    Int32 rW = realImg.Width;

                    Int32 fW = 170;
                    Int32 fH = (Int32)Math.Floor((double)rH * (fW / rW));
                    System.Drawing.Image thumbimg = realImg.GetThumbnailImage(fW, fH, null, IntPtr.Zero);

                    thumbimg.Save(Server.MapPath(_thumPath));
                    SavePicPath(_thumPath);

                }
            }
        }
        catch
        {
        }

任何时候它到达GetThumbnailImage我得到一个错误“内存不足”请任何更正或我做错了什么

1 个答案:

答案 0 :(得分:1)

将int值更改为(float或double)。我认为这里fw/rw返回int值而不是float或double值。