日期:2014-05-17  浏览次数:20736 次

想要一个上传图片的源码
我是刚学这个的,现在在做一个网站要用到这个功能,希望好人能给我一个这样的源码,最好能有注释,这样我就更容易看得懂了,我要的功能很简单:
1、可以限制图片的大小。
2、能指定上传的格式。
3、能实现缩略图。
大概就这些,谢谢好人了。

------解决方案--------------------
jquery 搜
------解决方案--------------------
string fileName = this.FileUpload_Import.PostedFile.FileName;
string _fileExt = fileName.Substring(fileName.LastIndexOf(".") + 1);
if (_fileExt.ToLower() != "txt")
{
ScriptHelper.AlertAndGoHistory("暂不允许导入除txt文件外的其他格式文件!", -1);
Response.End();
}
if (this.FileUpload_Import.PostedFile.ContentLength > 2097152)
{
ScriptHelper.AlertAndGoHistory("导入的文件大小不能超过2MB!", -1);
Response.End();
}
try
{
//上传读取导入的txt文件
string filePath = Server.MapPath("/Upload/") + this.FileUpload_Import.FileName;
this.FileUpload_Import.PostedFile.SaveAs(filePath);
string[] values = File.ReadAllLines(filePath);
//删除上传文件
System.IO.FileInfo file = new System.IO.FileInfo(filePath);
if (file.Exists)
{
file.Delete();
}
//将数据导入数据库
int success = 0;
if (SpreadCustomerInfo.BatchInsertInfo(values, out success))
{
ScriptHelper.AlertAndRedirect("导入完成,成功导入" + success.ToString() + "条数据", "/Manager/SMSSpreadUserInfo.aspx");
}
else
{
ScriptHelper.AlertAndRedirect("导入失败!", "/Manager/SMSSpreadUserInfo.aspx");
}
}
catch (Exception ex)
{
Logger.Error("导入数据失败:{0}", ex.ToString());
ScriptHelper.AlertAndRedirect("导入数据失败,导入文件错误!", "/Manager/SMSSpreadUserInfo.aspx");
}