日期:2014-05-18  浏览次数:20835 次

谁有图片上传代码/加注释给份
用来研究
      源码谢谢先

------解决方案--------------------
SaveAs 就可以了



还想要什么?
------解决方案--------------------
/// <summary>
/// 上传多个图片
/// by minjiang 07-08-01
/// </summary>
/// <param name= "sSavePath "> 原图路径 </param>
/// <param name= "sSaveSmallPath "> 小图路径 </param>
/// <param name= "preFileName "> </param>
/// <param name= "iMaxSize "> 大小 </param>
/// <param name= "iWidth "> 宽 </param>
/// <param name= "iHeight "> 高 </param>
/// <param name= "intSucess "> 统计有多少个图片已经成功上传 </param>
/// <param name= "arrFileNames "> 保存原图名称数组 </param>
/// <param name= "arrSmallFileNames "> 保存小图名称数组 </param>
/// <returns> </returns>

public string[] upPicture(string sSavePath, string sSaveSmallPath, string preFileName, int iMaxSize, int iWidth, int iHeight,int intSucess, out ArrayList arrFileNames, out ArrayList arrSmallFileNames)
{
arrFileNames = new ArrayList();
arrSmallFileNames = new ArrayList();
HttpFileCollection files = HttpContext.Current.Request.Files;
string strfileoldpath; //上传原图片的保存路径
string strfileoldname;//图片保存后名称
string strfilesmallpath; //小图片的保存路径
string strfilesmallname;//小图片保存后名称

string fileName, fileExtension;
string[] arrayImageUrl = new string[4] { " ", " ", " ", " " };
int iSucess = 0;//统计有多少个图片已经成功上传
try
{
for (int iFile = 0; iFile < files.Count; iFile++)
{
/// '检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
//没有文件上传
if (postedFile.FileName == " ")
{
arrayImageUrl[2] = "errorNoFile ";
continue;

}


fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName == " ")
{
arrayImageUrl[2] = "errorNoFile ";
continue;

}

fileExtension = System.IO.Path.GetExtension(fileName);
//判断上传文件类型
string filetype = postedFile.ContentType;
//判断是否图片
if ((filetype.IndexOf( "image ") == -1) || (fileExtension.Trim().ToLower() != ".jpeg ") && (fileExtension.Trim().ToLower() != ".jpg ") && (fileExtension.Trim().ToLower() != ".gif "))
{
arrayImageUrl[2] = "errorT ";
continue;
}

//判断是否图片大小超过上限
int MaxFile = 0;
MaxFile = postedFile.ContentLength;
if (MaxFile > (iMaxSize * 1024))
{
arrayImageUrl[2] = "errorb ";