C#_Fileuploadify_notMvc
<%@ 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的更多相关文章
随机推荐
- 仿酷狗音乐播放器开发日志二十六 duilib在标题栏弹出菜单的方法
转载请说明原出处,谢谢~~ 上篇日志说明了怎么让自定义控件响应右键消息.之后我给主窗体的标题栏增加右键响应,观察原酷狗后可以发现,在整个标题栏都是可以响应右键并弹出菜单的.应该的效果如下: 本以为像上 ...
- private
成员变量私有化的好处在于可以强制加强面向对象和封装的概念,一个面向对象的系统更加关注行为,而不是数据,所以应该通过发送消息来获得数据,也应该实习细节的封装
- 怎么利用SQL语句查询数据库中具体某个字段的重复行
select * from [tablename] group by SeriNohaving count(SeriNo)<>1
- 分类算法之朴素贝叶斯分类(Naive Bayesian Classification)
1.什么是分类 分类是一种重要的数据分析形式,它提取刻画重要数据类的模型.这种模型称为分类器,预测分类的(离散的,无序的)类标号.例如医生对病人进行诊断是一个典型的分类过程,医生不是一眼就看出病人得了 ...
- linux常用命令[持续更新]
top 察看系统状态,退出按q ps -A 察看所有进程 ps -A|grep gcalc|awk '{print $1}'|xargs kill 杀掉所有gcalc进程
- post和put的区别
post : 标识的是处理请求中资源表述的资源 put : 标识的是请求的资源表述 post : 支持多种类型的资源 put : 支持单一的资源
- 【转】Nginx系列(二)--模块化
原博文出于: http://blog.csdn.net/liutengteng130/article/details/46700977 感谢! 高度模块化的设计设Nginx架构的基础.在Nginx中 ...
- Codeforces 622B The Time 【水题】
B. The Time time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Spring的ControllerAdvice注解
@ControllerAdvice,是spring3.2提供的新注解,其实现如下所示: @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUN ...
- MSSQL索引优化
转自:http://blog.itpub.net/16436858/viewspace-589275/ http://www.cnblogs.com/jams742003/archive/2011/1 ...