惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
D
DataBreaches.Net
F
Full Disclosure
腾讯CDC
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
Project Zero
Project Zero
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
Schneier on Security
Schneier on Security

博客园 - 小飞虫

遍历 Session,Cookie,Application JS获取URL参数值 - 小飞虫 - 博客园 PHP时间戳 Mysql 备注数据库脚本 gridview 为CommandArgument绑定行号 .net 3.5 属性简写 有效解决CSS兼容性的技巧 DropDownList绑定枚举类型 如何避免DropDownList绑定无效值时抛出异常 网上找的JS身份证验证,修复了一个日期验证的bug 几个js的正则表达式验证 通过javascript修改文本框内容后提交 正则表达表手机号码 修改成员管理默认的密码规则 js密码验证 js邮件地址验证脚本 .net2.0邮件发送程序 从框架中关闭浏览器的JS脚本 关于web.config的问题
asp.net 上传图片并生成缩略图
小飞虫 · 2007-01-10 · via 博客园 - 小飞虫

    bool fileOK = false;
        
string path = Server.MapPath("~/Upload")+"\\";      //上传路径
        
if (fupImgUrl.HasFile)
        
{
            
string fileExtension = System.IO.Path.GetExtension(fupImgUrl.FileName).ToLower();   //获取要上传文件的扩展名

            
string[] allowedExtensions =".gif"".png"".jpeg"".jpg" };
            
for (int i = 0; i < allowedExtensions.Length; i++)
            
{
                
if (fileExtension == allowedExtensions[i])
                
{
                    fileOK 
= true;
                }

            }

        }


        
string fileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() +DateTime.Now.Hour.ToString()+ DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + System.IO.Path.GetExtension(fupImgUrl.FileName).ToLower();   //生成随机的文件名
        if (fileOK)
        
{
            
try
            
{
                fupImgUrl.PostedFile.SaveAs(path 
+ fileName);  //上传原图
                System.Drawing.Image image, sImage;
                image 
= System.Drawing.Image.FromStream(fupImgUrl.PostedFile.InputStream);
                
int width = image.Width;
                
int height = image.Height;
                
int NewWidth, NewHeight;
                
if (width > height)
                
{
                    NewWidth 
= 150;
                    NewHeight 
= NewWidth*height / width;
                }

                
else
                
{
                    NewHeight 
= 150;
                    NewWidth 
= NewHeight*width / height;
                }

                sImage 
= image.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);
                
int x, y;
                x 
= sImage.Width / 2 - 30;
                y 
= sImage.Height - 20;
                System.Drawing.Bitmap output 
= new System.Drawing.Bitmap(sImage);
                System.Drawing.Graphics g
= System.Drawing.Graphics.FromImage(output);
                System.Drawing.Font Fonts 
= new System.Drawing.Font("Courier New"9);
                g.DrawString(
"水印内容。。。。", Fonts, new System.Drawing.SolidBrush(System.Drawing.Color.Red), x, y);
                output.Save(path 
+ "s\\" + fileName, System.Drawing.Imaging.ImageFormat.Jpeg);

                Response.Write(
"<script>alert('上传文件成功')</script>");
                lbFileName.Text 
="~/upload/"+fileName;
                lbImages.Text 
= "~/upload/s/" + fileName;
            }

            
catch (Exception ex)
            
{
                Response.Write(
"<script>alert('"+ex.Message+"')</script>");
            }

        }

        
else
        
{
            Response.Write(
"<script>alert('无效的文件类型')</script>");
        }