图片上传判断width 等比例压缩
来源:互联网 发布:什么是php-fpm 编辑:程序博客网 时间:2024/06/06 08:40
HttpPostedFile oFile = Request.Files["NewFile"];
// Check if the file has been correctly uploaded
if (oFile == null || oFile.ContentLength == 0 || !(Convert.ToInt32(HttpContext.GetGlobalResourceObject("SystemInfo", "OpenFileup")) == 1))
{
SendResults(202);
return;
}
int iErrorNumber = 0;
string sFileUrl = "";
// Get the uploaded file name.
string sFileName = System.IO.Path.GetFileName(oFile.FileName).Substring(System.IO.Path.GetFileName(oFile.FileName).LastIndexOf(".") + 1).ToLower();
string TypeName = HttpContext.GetGlobalResourceObject("SystemInfo", "UpfileTypeSettings").ToString();
if (!TypeName.Contains(sFileName) ||
oFile.ContentLength >= Convert.ToInt32(HttpContext.GetGlobalResourceObject("SystemInfo", "MaxFileLengthSettingsKB")) * 1024)
//文件类型判断 文件大小验证
{
SendResults(202);
return;
}
int iCounter = 0;
while (true)
{
//判断文件是否可以上传
if (CheckUploadFileExtension(sFileName))
{
string sFilePath = System.IO.Path.Combine(this.UserFilesDirectory, sFileName);
if (System.IO.File.Exists(sFilePath))
{
iCounter++;
sFileName =
System.IO.Path.GetFileNameWithoutExtension(oFile.FileName) +
"(" + iCounter + ")" +
System.IO.Path.GetExtension(oFile.FileName);
iErrorNumber = 201;
}
else
{
if (TypeName.Contains(".gif") || TypeName.Contains(".jpg") || TypeName.Contains("bmp") || TypeName.Contains("png"))
{
System.Drawing.Image image = System.Drawing.Image.FromStream(oFile.InputStream);
int width = image.Width;
int height = image.Height;
int max = Convert.ToInt32(HttpContext.GetGlobalResourceObject("SystemInfo", "ImageMaxWidth"));
if (width > max)
{
try
{
System.Drawing.Image newPic; //定义新位图对象
//String picPath = path + userID + time + fileExtension;
if (width > height)
{
newPic = new Bitmap(image, max, height * max / width); //缩放
}
else
{
newPic = new Bitmap(image, width * max / height, max); //缩放
}
newPic.Save(sFilePath, System.Drawing.Imaging.ImageFormat.Bmp); //将处理后的图片保存成bmp文件
sFileUrl = this.UserFilesPath + sFileName;
break;
}
catch
{
}
}
}
oFile.SaveAs(sFilePath);
sFileUrl = this.UserFilesPath + sFileName;
break;
}
}
else
{
//不允许上传
SendResults(202);
break;
}
}
SendResults(iErrorNumber, sFileUrl, sFileName);
- 图片上传判断width 等比例压缩
- 图片上传判断width 等比例压缩
- 上传 图片 等比例压缩
- 上传等比例压缩图片
- 等比例压缩图片
- 图片等比例压缩
- 图片等比例压缩
- php实现上传图片和等比例缩略图压缩图片
- 上传缩略图,等比例压缩
- js图片等比例压缩
- 图片等比例压缩方法
- iOS等比例压缩图片
- php图片等比例压缩
- java等比例压缩图片
- php等比例压缩图片
- python图片等比例压缩
- java上传并压缩图片(等比例压缩或者原尺寸压缩)
- 判断图片等比例缩小
- APPlication,Session和Cookie的区别
- Documentation Library
- 变速器 美国sram速联和日本shimano洗马路对比
- 从vs2005或者vs2008迁移到vs2010链接错误: fatal RC1106: invalid option: -ologo 修正方法
- ubuntu下LVS + Keepalived 实现mysql高可用负载均衡实现
- 图片上传判断width 等比例压缩
- 给流量测量程序加入Bloom Filter出现的问题
- qeePHP Qform表单验证方法介绍
- 最简单的servlet程序【使用Eclipse】
- ssh整合常见问题及解决方案
- linux 命令行 下sftp操作命令
- Android系统触摸屏的校正——http://carvencao.blog.sohu.com/156057534.html
- 各种资源下载地址收集
- 互联网技术架构积累1