<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="jqUploadify._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<link href="scripts/uploadify.css" rel="stylesheet" type="text/css" />
<link href="scripts/default.css" rel="stylesheet" type="text/css" /> <script src="scripts/jquery-1.7.2.min.js" type="text/javascript"></script> <script src="scripts/swfobject.js" type="text/javascript"></script> <script src="scripts/jquery.uploadify.min.js" type="text/javascript"></script> <script type="text/javascript">
$(function(){
$("#file_upload").uploadify({
//开启调试
'debug' : false,
//是否自动上传
'auto':false,
'buttonText':'选择照片',
//flash
'swf': "scripts/uploadify.swf",
//文件选择后的容器ID
'queueID':'uploadfileQueue',
'uploader':'scripts/upload.ashx',
'width':'',
'height':'',
'multi':false,
'fileTypeDesc':'支持的格式:',
'fileTypeExts':'*.jpg;*.jpge;*.gif;*.png',
'fileSizeLimit':'1MB',
'removeTimeout':, //返回一个错误,选择文件的时候触发
'onSelectError':function(file, errorCode, errorMsg){
switch(errorCode) {
case -:
alert("上传的文件数量已经超出系统限制的"+$('#file_upload').uploadify('settings','queueSizeLimit')+"个文件!");
break;
case -:
alert("文件 ["+file.name+"] 大小超出系统限制的"+$('#file_upload').uploadify('settings','fileSizeLimit')+"大小!");
break;
case -:
alert("文件 ["+file.name+"] 大小异常!");
break;
case -:
alert("文件 ["+file.name+"] 类型不正确!");
break;
}
},
//检测FLASH失败调用
'onFallback':function(){
alert("您未安装FLASH控件,无法上传图片!请安装FLASH控件后再试。");
},
//上传到服务器,服务器返回相应信息到data里
'onUploadSuccess':function(file, data, response){
//alert(data);
}
});
}); function doUplaod(){
$('#file_upload').uploadify('upload','*');
} function closeLoad(){
$('#file_upload').uploadify('cancel','*');
} </script> </head>
<body>
<table width="" border="" align="center" cellpadding="" cellspacing="" id="__01">
<tr>
<td align="center" valign="middle">
<div id="uploadfileQueue" style="padding: 3px;">
</div>
<div id="file_upload">
</div>
</td>
</tr>
<tr>
<td height="" align="center" valign="middle">
<img alt="" src="data:images/BeginUpload.gif" width="" height="" onclick="doUplaod()" style="cursor: hand" />
<img alt="" src="data:images/CancelUpload.gif" width="" height="" onclick="closeLoad()" style="cursor: hand" />
</td>
</tr>
</table>
</body>
</html>
using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.SessionState;
using System.IO; namespace jqUploadify.scripts
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class upload : IHttpHandler, IRequiresSessionState
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8"; HttpPostedFile file = context.Request.Files["Filedata"];
string uploadPath = context.Server.MapPath("..\\uploads\\"); if (file != null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
file.SaveAs(uploadPath + file.FileName);
//生成缩略图
MakeThumbnail(uploadPath + file.FileName, uploadPath + "\\s\\" + file.FileName, , );
}
} private void MakeThumbnail(string sourcePath, string newPath, int width, int height)
{
System.Drawing.Image ig = System.Drawing.Image.FromFile(sourcePath);
int towidth = width;
int toheight = height;
int x = ;
int y = ;
int ow = ig.Width;
int oh = ig.Height;
if ((double)ig.Width / (double)ig.Height > (double)towidth / (double)toheight)
{
oh = ig.Height;
ow = ig.Height * towidth / toheight;
y = ;
x = (ig.Width - ow) / ; }
else
{
ow = ig.Width;
oh = ig.Width * height / towidth;
x = ;
y = (ig.Height - oh) / ;
}
System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.Clear(System.Drawing.Color.Transparent);
g.DrawImage(ig, new System.Drawing.Rectangle(, , towidth, toheight), new System.Drawing.Rectangle(x, y, ow, oh), System.Drawing.GraphicsUnit.Pixel);
try
{
bitmap.Save(newPath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
throw ex;
}
finally
{
ig.Dispose();
bitmap.Dispose();
g.Dispose();
} } public bool IsReusable
{
get
{
return false;
}
}
}
}

C#_Fileuploadify_notMvc的更多相关文章

随机推荐

  1. C++程序设计之结构体,共用体,枚举和typedef

    [1]结构体的基本功 注意结构体里面可以有很多东西,可以结构体里面包含结构体 #include<iostream> using namespace std; struct Date { i ...

  2. 【原】Mongodb相关资料

    Mongodb与关系型数据库对比 Mongodb与关系型数据库对比 由于之前主要接触的是关系型数据库,所以主要将Mongodb与关系型数据库进行对比:主要从术语.Server与Client.数据定义语 ...

  3. UIButton 在 iOS7.0与iOS7.1 中关于enabled的一点区别

    前些日子,在一台iOS7.0的设备上进行调试,关于UIButton的一部分代码如下 1 self.btn_loadmore.enabled = NO; 2 [self.btn_loadmore set ...

  4. [Hive - LanguageManual] GroupBy

    Group By Syntax Simple Examples Select statement and group by clause Advanced Features Multi-Group-B ...

  5. MapReducer Counter计数器的使用,Combiner ,Partitioner,Sort,Grop的使用,

    一:Counter计数器的使用 hadoop计数器:可以让开发人员以全局的视角来审查程序的运行情况以及各项指标,及时做出错误诊断并进行相应处理. 内置计数器(MapReduce相关.文件系统相关和作业 ...

  6. linux常用命令[持续更新]

    top 察看系统状态,退出按q ps -A 察看所有进程 ps -A|grep gcalc|awk '{print $1}'|xargs kill 杀掉所有gcalc进程

  7. Java邮件服务学习之四:邮箱服务客户端Spring Mail

    一.Spring Mail API Spring邮件抽象层的主要包为org.springframework.mail,Spring提供的邮件发送不仅支持简单邮件的发送.添加附件. 1.邮件发送的核心接 ...

  8. 注意 sizeof 中不要有复杂运算操作

    http://github.tiankonguse.com/blog/2014/12/05/c-base/ 一个比较有意思的问题 #include<stdio.h> ; int f() { ...

  9. FrameWork 建模时查询项的usage

    § Identifier:代表被用于分组或汇总与其相关的Fact数据的列.也代表一个索引列.还代表日期或时间列.§ Fact:代表一个包含数值数据可被分组或汇总的列,例如,产品成本.§ Attribu ...

  10. Oracle的回收站和闪回查询机制(一)

    实际工作中,我们经常会遇到一些情况,误删除某些表或某些表的某些记录,这时候就需要我们将这些记录重新插入进去.如何才能解决这个问题呢? Oracle的Flashback query(闪回查询)为我们解决 ...